Monday, March 28, 2011

Adding custom log locations to the OS X console application...

After searching online, the best solution I've found so far is to just make a symbolic link in either "/Library/logs/" or "~/Library/logs/" to get it to show up in the Console application.

I'm wondering if it would be possible to add a new directory or log file to the "root" level directly under the "LOG FILES" section in the console.

Here's a quick screenshot:

OS X Console

From stackoverflow
  • I don't believe it's possible.

    If you're generating log files, you should generate them into one of the standard locations anyway, so this won't be an issue.

  • There is one way to get you log files into the console.

    You can add a symlink to the log file or log directory to one of the directories in the list. The directory ~/Library/Logs seems like the logical choice for adding your own log files.


    For myself I wanted easy access to apache2 logs. I installed apache2 using macports and the default log file is located at /opt/local/apache2/logs.

    Thus all I did was create the symlink to that directory.

    # cd ~/Library/Logs
    # ln -s /opt/local/apache2/logs/ apache2
    

    Now I can easily use the console.app to get to the logs.

  • In Terminal run this command... append any log file directories you want to add

    defaults write com.apple.Console LogFolderPaths -array '~/Library/Logs/' '/Library/Logs/' '/var/log/' '/opt/local/var/log/'

    Ted Naleid : This didn't seem to work for me on Leopard 1.5.7, am I missing something?
    Wilco : Doesn't work for me either (sasme OS/version) - any ideas?
    sholsinger : Sorry I thumbed it up before trying. That default doesn't exist.
  • I actually just came across this option that worked perfectly for me:

    Actually if you open terminal and...

    $ cd /Library/Logs

    then sym-link to your new log directory. eg i want my chroot'ed apache logs as 'www'

    $ ln -s /chroot/apache/private/var/log www

    then re-open Console.app

    drill down into /Library/Logs and you will find your sym-linked directory.

    ;-)

    Mohclips.

    http://forums.macosxhints.com/showthread.php?t=35680

How can AWK do array arithmetics?

I want to shift away from Excel to Awk. I need basic mathematical operations, such as addition and division, for arrays.

For example, arrays A and B are [1, 3, 2] and [2, 1, 2], respectively. How can I get an array [2, 3, 4] from the multiplication between A and B? What about the addition and division between A and B?

From stackoverflow
  • I think awk is not done for this sort of numeric work. It's more for text processing. Arrays in awk are associative and sparsely occupied (may have "holes" between its indexes). You use strings to index them:

    for(int j=0; j<length(A) && j<length(B); j++)
        C[j] = A[j] * B[j]
    

    It's like a hash-map. So, in awk you can do

    A[100] = 10;
    A[1] = 2;
    

    And have only 2 elements stored in that array (elements from 2 to 99 do not exist), indexed by strings that are created by converting the numbers 100 and 1. The GNU Awk manual has a nice section about arrays in awk here.

  • In awk "arrays" are associative. That is they are hashes indexed not by a continous string of numbers but by arbitrary input values. So you can do things like

    for (i=0; i<3; i++){
       c[i] = a[i] * b[i];
    };
    

    if you know that the numerically indexed elements exist, or you can do things like:

    d["sam"] = a[3] + b["dog"];
    

    But array processing really isn't awk's strength, and I would advise taking a careful look at what is involved before committing wholesale to this course.

    You might be better off with python or another fairly modern rapid development language.

    BTW-- I wrote my first non-trivial bit of code in python last week, and I am totally hooked. After occasional exposure to tcl and perl, I was really wishy-washy on the value of these kinds of tools. I think python will make a believer out of me.

Data handling in web app with GWT, Struts and Hibernate

I am writing a Web App using Struts and Hibernate. Recently, I discovered GWT and the Visualization API. This all looked very interesting and provides AJAX functionalities that my app needs. I'm a newbie that is quite confused....

Where to put data access level checks?

In the web app, users have different level of access for the data. e.g. different combinations of read/write privileges for different data. There will be some kind of user profile that the app checks for when any data is accessed or modified. The user will be given data access according the result -- denied viewing access or can see the data but cannot change it etc. I'm not sure where to put this particular check. I guess I could have it coded in the DAO's, everytime data operation is processed, manually check the queried data against the profile. Or, put it in the business logic/display layer, if an user does not have a data access privilege, take the button away from the user. Or both? Or is there a configuration file in hibernate somewhere I can specify data access privileges for all the tables mapped?

Best practice for passing information around

There is great need to communication between the model/view/controller, make RPC call for GWT and pass data off to the Visualization code to render charts and stuff. I'm guessing it definitely need some kind of translator that converts Java objects into JSON objects in order to make gwt-rpc calls and draw charts with the Visualization API. Am I correct? Also, in terms of passing information around in Struts and Hiberante -- is writing Data Transfer Objects a good idea? Then just pass beans around all the time? Or (I just came across this today..not even sure if I understood it correctly) maybe bind the objects onto JNDI, and access them from other parts of the program?

Any input/clarification will be appreciated. Thank you very much!

From stackoverflow
  • I can't speak much about your first question because I really don't like using Struts for anything GWT related.

    As to your second question, no you shouldn't have to use any JSON. It sounds like your back end is Java, which means that the GWT RPC mechanism will just work with POJOs. So you would just create the objects you need for drawing and pass them back and forth between your client and server. GWT will do all the RPC stuff for you out of the box.

    Writing Data Transfer objects might be necessary, but only if your hibernate model files contain things that the GWT compiler can't understand. I normally user EJB3 and Stripes (instead of Hibernate and Struts) and in my case I never have to write any data transfer objects, I just use the EJB3 POJOs and pass them between my client and server.

    Chii : if you use hibernate, your domain object can not be serialized by gwt, even if it only contains gwt serializable objects. thats because hibernate proxies the results, especially sets/lists. you will beed DTO's unless the objects participating in rpc are not from hibernate.
    tomato : Thanks for your input! I still have to explore more about RPC...
  • access level checks:

    i would seperate the access level checks into its own class, and have your "controllers" call the access managers first before calling DAO's. i.e., each action performs a check before doing the DAO calls to get/insert data.

    but a better method, if you are using gwt, is to make RPC calls instead of using struts actions. the rpc calls becomes the "controllers" i mentioned above, and can do access checks using the managers i mentioned above - i.e., elminitate actions.

    as for the access managers, i recommend enumerating all granular access privileges, and the compose these priviledges into a set that can be associated with each user/profile/whatever.

    passing info around gwt is a pain to work with hibernate - you can try using Gilead , but i havent had much success with it, its too cumbersome for me. your idea with json converting is the right way to go in gwt imho. gwt 1.5 supports whats called javascript object overlay, which lets you return json, and "superimpose" it into a gwt java object directly with little code on your part. check out this post for more info.

    the other method is to roll your own DTO generation facility (which is what Gilead is meant to do, but i dont think it does autogeneration?not sure). implement it as part of your build. its a bit of extra work that wouldnt be worth it if its not a large project.

  • Data access level checks in server side is the safest way. But still GWT generates a packed JS. You can do it on Client side. But in that case user profile should be checked/fetched in/from the server side every time.

    passing info around: I am using delimited strings in vector. And it is running good...

How to best develop web crawlers

Heyall,

I am used to create some crawlers to compile information and as I come to a website I need the info I start a new crawler specific for that site, using shell scripts most of the time and sometime PHP.

The way I do is with a simple for to iterate for the page list, a wget do download it and sed, tr, awk or other utilities to clean the page and grab the specific info I need.

All the process takes some time depending on the site and more to download all pages. And I often steps into an AJAX site that complicates everything

I was wondering if there is better ways to do that, faster ways or even some applications or languages to help such work.

From stackoverflow
  • Using regular expressions for parsing content is a bad idea that has been covered in questions here countless times.

    You should be parsing the document into a DOM tree and then you can pull out any hyperlinks, stylesheets, script files, images or other external links that you want and traverse them accordingly.

    Many scripting languages have packages for getting Web pages (eg curl for PHP) and for parsing HTML (eg Beautiful Soup for Python). Go that route instead of the hackky solution of regular expression matching.

  • If you use python, Scrapy is great is easy to use.

Floorplan and packaging architecture resources for the interested software professional?

One of the more interesting things I've run into lately is the art and science of laying out chip floorplan and determining packaging for the silicon. I would like to read some materials on the subject for the "Interested Software Guy".

Does anyone have any recommendations (Website or book, so long as it is a good quality)?

From stackoverflow
  • This is a result of my search on the subject as I was curious about your question and this is where I would start myself. Sorry I am not a specialist on the subject but hope it can kick-start you!

    Seems floorplan optimization is a matter of combinatorial optimization.

    As a developer, you'll want to tackle the theory behind it and most likely some proven algorithms. You might then be interested by books such as:

    It's a bit more difficult to get links on this subject, but if you're a member of IEEE Xplore, you might want to look at this paper and other similar ones.

    Finally, on the floorplan wikipedia entry, you'll notice this on sliceable floorplans that might give you your best starting point:

    Sliceable floorplans have been used in a number of early EDA tools for a number of reasons. Sliceable floorplans may be conveniently represented by binary trees which correspond to the order of slicing. What is more important, a number of NP-hard problems with floorplans have polynomial time algorithms when restricted to sliceable floorplans

    Good luck!

    BCS : Nice, a hard copy list. Their sure is something to be said for good old bound paper. +1
    lpfavreau : It was a pleasure, hope it helps!
  • There seems to be a class on this at Carnegie Mellon

    VLSI CAD

    some of the lecture notes that looked more interesting than others:

    That site make references to one or more books that this fellow published:

    Also I found a short tutorial here

  • AutoCAD is a classic... Though on my limited budget I prefer Rhino 2.0.

Best way to store Badge criteria?

I've been thinking about how to implement the badge feature similar to SO's on a new website. What is the best way to store criteria for badges?

Two ideas:

  • All code
  • 'Second system' - create a meta architecture for defining badges and their criteria. Store some info in the database and have code query it to figure out the badges and their criteria.

Are there better ways?

From stackoverflow
  • Rules.

    You create events in the system, and use rules within an event stream processor.

    Specifically, say you have a badge "made 10 posts". You don't run "select count(*) from posts where user = :user" for every post. Rather, you have a simple rule that watches each post come by, and "count them", storing the rules state in the user profile.

    That way "made 10 posts" is as cheap as "made 1,000,000" posts.

    This also makes the system much more extensible.

    Doug McClean : If you go this route, be careful of the cases when you add a new badge and need to analyze what existing users should have already earned it.
    Will Hartung : Yes, absolutely a downside of the system, but still its more flexible and scalable as (typically) adding new badges happens far less than testing and awarding them.
    Micah : So how would you handle adding badges down the road? Let 's say I have a new badge like the "woot" badge that SO added. How would you make it retroactive?
    Will Hartung : You would need to have some mechanism to rerun the event history data to accumulate the statistics necessary for your new badge and bring it up to date.
  • I agree with Will on this one.

    Create "events" over the pages so every time an event happens ie. a user deletes a post, it will query the event module with the event, lets say, EVENT_USER_DELETE_POST and then you can select that event and build a query based on it. You can then decide if a badge is awarded or not.

    This will keep the two logics seperate and keep a modular design. It should be very easy to implement this way.

    The only downside is that if the event was not "captured" then a user may well have earned a badge criteria but it has not yet been rewarded. However, this should never occur. The only situation I can think of is if the database is manipulated manually.

In Eclipse, how do I change perspectives after terminating a process?

So Eclipse by default automatically switches to the Debug perspective when you hit a breakpoint. However, it is annoying me that it doesn't automatically switch back to the previous perspective (say, Java) when terminating the process. It just stays in the debug perspective even though there is nothing to debug because nothing is running.

Is this possible?

From stackoverflow
  • you would need to write eclipse plugin

    here i found example how in plugin switch perspective

    helifreak : I am surprised that such a fundamental user interaction is missing from what is supposedly the worlds most used IDE.
  • To complete mark's answer, that option tells Eclipse when to switch to the associated perspective upon program suspension - meaning when a breakpoint is hit, it will switch to Debug perspective.

    Switching back to another perspective after you're done debugging has to be manual

    alt text

    If you want to avoid it switching to Debug in the first place, you can choose "Never" as the option.

    alt text

    If you want to switch back in the situation where the debugged program terminates normally (Not when you want to stop debugging it yourself), you may hope Eclipse figures out that your program terminates normally and switch to a "default" perspective at that time...

    However, there is no notion of "default" perspective, so how would Eclipse knows which one to switch to ? (the "Preferences/Perspectives/Make default" is only for the "Open Perspective" dialog, but that may not be the same perspective than the one you actually want to switch back to after a debug)

    alt text

    Also, should Eclipse closes the Debug perspective or just changes to a different one ?
    What if there is more than one program running -- when one terminates, you might still be interested in debugging the other one, or maybe not.

    The point is, the decision about when to change perspective (and what perspective to change to) is not reasonable for the machine to make -- it requires a person knowing what he wants to do next.

    Joe Ludwig : I agree with everything but "is not reasonable for the machine to make ". Visual Studio does a fine job by returning to the main view when there are no processes left to debug.
    VonC : @Joe Ludwig: agreed. Eclipse may be victim of its own complexity, tricking itself into *not* offering this feature.
    VonC : @Joe Ludwig: btw, sorry: I did not play at Pirate: I am not so much into MMO... Right now, I play GTAIV (solo) ;)
    helifreak : I think the appropriate solution would be to switch back to the previous perspective that I was in before the debug perspective, if all debug sessions have ended. As Joe mentioned, Visual Studio, and all other IDEs i've used do this by default.
  • I filed a bug for this:

    https://bugs.eclipse.org/bugs/show_bug.cgi?id=327983