lundi 1 décembre 2014

How to catch mount events on Linux?


I want to somehow get notified if a mount or unmount occurs for a USB drive. Is there a way to do this?


At the moment I use udev and then wait for x seconds for a new entry in /proc/mounts. This works ok if the mounting is automatic. However this won't work if the user unmounts and then mounts the device manually.


Is there a way to catch those events?





Why don't set a Trial Period when it comes to publishing my app


I'm sorry if i have elected the wrong Forum for this Kind of question..


Hello communitiy,


i thought about a new way to publish my app. I don't want to make it completely free and i don't want to Show ads. That's because i spent hours to get the best Performance in start up and executing. (Ads take Long to be displayed, because they Need to be downloaded. And of course, they are annoying).


I also want to get free of the idea to make only half of the app accessible regarding to the free Version of my app..


So i thought about, why not give every user the full Version of my app for free and set a timer so that they can try and examine the app for a specific time. If they like it, they can buy, if not the app get unaccessible.


The simple code would look like this:



PackageInfo myPackageInfo = getPackageManager().getPackageInfo("com.android.myPackage", null);
myPackageInfo.firstInstallTime;


and over the System time i can determine if the Trial period is expired.


For sure, the user can now set back his System Time which will cause bad effects on his Alarm clock. Or he can simply uninstall the app and download it again. But in my app you can make many customized configurations, which i think will prevent most users from uninstall and reinstall the app again every 6 hours for example( if i set the Trial period to 6 hours). I think this Kind of Trial period is not unkown, many Softwares for Windows(i'm only up to date at Windows) have Trial Periods. And they use the Trial-period-idea since years.


So,


The Question


Why do i never see a app which got a Trial period. Is this prevented by Google. Or is it just a psychological Point regarding to applications.





Why have some websites started encoding "ff" as a single character "ff"?


For example in Aeon:



what leads us to consider another person as no longer the same. One might think that a different set of rules applies to assessments of one’s own continuity – perhaps episodic memory is paramount from this perspective



What's the motivation? And why have I started seeing this only now? I expect some tooling somewhere has changed?


PS what is this "ff" charaer called?





On-the-fly, random partition of a range of numbers [0,N] in groups of max M size


Hi collective unconscious,


Suppose that you have a range of numbers from 0 to N that you want to randomly separate in groups of max M sequential numbers. This is easily done with a bitmap and a random number generator, but it is not space efficient for very large instances of N.


So, what I want is a generator that, given a number N and M, will start producing non-overlapping groups in a random order and with random size, with less than O(n) space efficiency.


E.g. for N = 7 and M = 3, a valid output is the following:



4
1, 2
3
5, 6, 7
0


Does anyone know an algorithm that can help in producing such an output?





Java App as Tomcat Service?


I currently have a basic j2ee website. Currently, a jsp frontend gets data from the backend (the java program, lets call it object "Score"). The backend gets this data from a web site.



<% Main m = new Main(5); %>
<table style="width: 100%">
<tr>
<th align="left">NBA</th>
<th style="text-align: right"><%=m.getTime("nba")%></th>
</tr>
</table>
<% Iterator itrNba = m.getNbaM().entrySet().iterator();
for (Map.Entry<Integer, Match> entry : m.getNbaM().entrySet()) {
Match value = entry.getValue(); %>


However, this only happens once. If the user wants new data, they have to refresh the page, the backend will run the algorithm to populate some objects (hashmaps), and the jsp displays the values.


The backend data is sports scores and I want this to be a live feed. Therefore I have to make the back end poll the source, and the front end poll the backend (not necessarily the same intervals either).


How can I make my data objects persist? With my current implementation, every time the page is loaded, a new Score, when Score should be the same for all clients (the frontend jsp). So I made my data objects static and I put the main entry point in a loop, and it isnt working.


Im thinking my main java Scores object needs to be run as a service. Do I need to use servlets here?


Is there an easy way to accomplish what Im describing?





Should I use a class as a wrapper?


Lets say I have a class representing a chemical compound



class Compound(networkx.Graph):

def __init__(self):
super(Compound, self).__init__()


And lets say that I want to add some extra functionality onto a chemical compound. It should probably inherit from Compound. But is it okay to just use it as a wrapper for Compound? For example



class Acid(Compound):

def __init__(self, compound, *other_data):
self.__dict__.update(compound.__dict__)


Basically, this class would just have pointers to the underlying class and then let me add functionality without having to copy things. Does this make sense? Is it reasonable? Am I even doing it right?





dimanche 30 novembre 2014

Enumerating array in reverse order using size_t index


Let's say we need to print int array with size N in reverse order:



// Wrong, i is unsigned and always >= 0:
for(size_t i = N-1; i >= 0; --i){cout << data[i];}

// Correct, but uses int instead of size_t:
for(int i = N-1; i >= 0; --i){cout << data[i];}

// Correct, but I don't like this:
size_t counter = N-1;
for(size_t i = 0; i < N; ++i){cout << data[counter--];}


Is there elegant way to do such enumeration without additional variable and using size_t index?