Question:
I am looking for a more technical explanation than the OS calls the function.

Is there a website or book?

Answer:
```
main()
```
is part of the C library and is not a system function. I don't know for OS X or Linux, but Windows usually starts a program with
```
WinMainCRTStartup()
```
. This symbol init your process, extract command line arguments and environment (
```
argc, argv, end
```
) and calls
```
main()
```
. It is also responsible of calling any code that should run after
```
main()
```
, like
```
atexit()
```
.
By looking in your Visual Studio file, you should be able to find the default implementation of
```
WinMainCRTStartup
```
to see what it does.
You can also define a function of your own to call at startup, this is done by changing "entry point" in the linker options. This is often a function that takes no arguments and returns a void.


Question:
I thought that I had the latest CTP of PowerShell 2 but when I try the command:

invoke-expression –computername Server01 –command 'get-process PowerShell'

I get an error message:

A parameter cannot be found that matches parameter name 'computername'.

So the question is: How can I tell which version of PowerShell I have installed? And what the latest version is?

Answer:
```
$host.version.tostring()
```
will return the version number.
RTM of v1 is 1.0.0.0
Couldn't honestly tell you what the latest version of the previews are because I haven't had a chance to play yet.


Question:
For example; with the old command prompt it would be:

cmd.exe /k mybatchfile.bat

Answer:
Drop into a cmd instance (or indeed PowerShell itself) and type this:
```
```
powershell -?
```
```
You'll see that powershell.exe has a "-noexit" parameter which tells it not to exit after executing a "startup command".


Question: What's the DOS FINDSTR equivalent for PowerShell? I need to search a bunch of log files for "ERROR".

Answer:
Here's the quick answer
```
```
Get-ChildItem -Recurse -Include *.log | select-string ERROR
```
```
I found it
here
which has a great indepth answer!


Question:
In WindowsForms world you can get a list of available image encoders/decoders with

System.Drawing.ImageCodecInfo.GetImageDecoders() / GetImageEncoders()

My question is, is there a way to do something analogous for the WPF world that would allow me to get a list of available

System.Windows.Media.Imaging.BitmapDecoder / BitmapEncoder

Answer:
Hopefully someone will correct me if I'm wrong, but I don't think there's anything like that in WPF.  But hopefully this is one of the many cases where advances in the technology have rendered obsolete the way we're used to doing things.  Like "how do I wind my digital watch?"
To my understanding, the reason why ImageCodecInfo.GetImageDecoders() is necessary in System.Drawing has to do with the kludgy nature of System.Drawing itself: System.Drawing is a managed wrapper around GDI+, which is an unmanaged wrapper around a portion of the Win32 API.  So there might be a reason why a new codec would be installed in Windows without .NET inherently knowing about it.  And what's returned from GetImageDecoders() is just a bunch of strings that are typically passed back into System.Drawing/GDI+, and used to find and configure the appropriate DLL for reading/saving your image.
On the other hand, in WPF, the standard encoders and decoders are built into the framework, and, if I'm not mistaken, don't depend on anything that that isn't guaranteed to be installed as part of the framework.  The following classes inherit from BitmapEncoder and are available out-of-the-box with WPF: BmpBitmapEncoder, GifBitmapEncoder, JpegBitmapEncoder, PngBitmapEncoder, TiffBitmapEncoder, WmpBitmapEncoder.  There are BitmapDecoders for all the same formats, plus IconBitmapDecoder and LateBoundBitmapDecoder.
You may be dealing with a case I'm not imagining, but it seems to me that if you're having to use a class that inherits from BitmapEncoder but wasn't included with WPF, it's probably your own custom class that you would install with your application.
Hope this helps.  If I'm missing a necessary part of the picture, please let me know.


Question: How do you run an external program and pass it command line parameters using C? If you have to use operating system API, include a solution for Windows, Mac, and Linux.

Answer:
```
```
#include <stdlib.h>

int main()
{
    system("echo HAI");

    return 0;
}
```
```


Question: I have a process in Linux that's getting a segmentation fault.  How can I tell it to generate a core dump when it fails?

Answer:
This depends on what shell you are using.  If you are using bash, then the ulimit command controls several settings relating to program execution, such as whether you should dump core.  If you type
```
```
ulimit -c unlimited
```
```
then that will tell bash that its programs can dump cores of any size.  You can specify a size such as 52M instead of unlimited if you want, but in practice this shouldn't be necessary since the size of core files will probably never be an issue for you.
In tcsh, you'd type
```
```
limit coredumpsize unlimited
```
```


Question:
So, in your experience, whats the best way? Is there a secure way that's also scriptable/triggerable in a build automation tool?

Edit: I should mention this is windows/.net and I'll be deploying to iis6

Answer:
For some projects I use
Capistrano
to push out to live. It is built on top of ruby and makes deploy script writing super easy and uses ssh.
On other projects I have a tiny deploy app that uses bash to do an svn export to a temporary directory and then rsync it over to the live server. You can make rsync use ssh.
I greatly prefer the Capistrano method, even if your project isn't in ruby/rails.


Question:
I am writing a batch script in order to beautify JavaScript code. It needs to work on both Windows and Linux.

How can I beautify JavaScript code using the command line tools?

Answer:
First, pick your favorite Javascript based Pretty Print/Beautifier.  I prefer the one at
http://jsbeautifier.org/
, because it's what I found first.  Downloads its file
https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js
Second, download and install The Mozilla group's Java based Javascript engine,
Rhino
.  "Install" is a little bit misleading;  Download the zip file, extract everything, place js.jar in your Java classpath (or Library/Java/Extensions on OS X).  You can then run scripts with an invocation similar to this
```
```
java -cp js.jar org.mozilla.javascript.tools.shell.Main name-of-script.js
```
```
Use the Pretty Print/Beautifier from step 1 to write a small shell script that will read in your javascript file and run it through the Pretty Print/Beautifier from step one.  For example
```
```
//original code
(function() { ... js_beautify code ... }());

//new code
print(global.js_beautify(readFile(arguments[0])));
```
```
Rhino gives javascript a few extra useful functions that don't necessarily make sense in a browser context, but do in a console context. The function print does what you'd expect, and prints out a string.  The function readFile accepts a file path string as an argument and returns the contents of that file.
You'd invoke the above something like
```
```
java -cp js.jar org.mozilla.javascript.tools.shell.Main beautify.js file-to-pp.js
```
```
You can mix and match Java and Javascript in your Rhino run scripts, so if you know a little Java it shouldn't be too hard to get this running with text-streams as well.


Question:
Example:

select ename from emp where hiredate = todate('01/05/81','dd/mm/yy')

and

select ename from emp where hiredate = todate('01/05/81','dd/mm/rr')

return different results

Answer:
http://oracle.ittoolbox.com/groups/technical-functional/oracle-dev-l/difference-between-yyyy-and-rrrr-format-519525
YY allows you to retrieve just two digits of a year, for example, the 99 in
  1999. The other digits (19) are automatically assigned to the current
  century. RR converts two-digit years into four-digit years by rounding.
50-99 are stored as 1950-1999, and dates ending in 00-49 are stored as
  2000-2049. RRRR accepts a four-digit input (although not required), and
  converts two-digit dates as RR does. YYYY accepts 4-digit inputs butdoesn't
  do any date converting
Essentially, your first example will assume that 81 is 2081 whereas the RR one assumes 1981. So the first example should not return any rows as you most likely did not hire any guys after May 1 2081 yet :-)


Question:
What is a good free library for editing MP3s/FLACs.

By editing I mean:

Cutting audio file into multiple parts

Joining multiple audio files together

Increase playback speed of file without affecting the pitch (eg. podcasts up to 1.3x)

Re-encoding audio file from Flac -> MP3 or vice versa

I don't mean software, I mean a library that I can use within another application. Programming language agnostic.

Answer:
I use
Audacity
for all my editing needs
Audacity is a free, easy-to-use audio
  editor and recorder for Windows, Mac
  OS X, GNU/Linux and other operating
  systems. You can use Audacity to:
```
```
* Record live audio.
* Convert tapes and records into digital recordings or CDs.
* Edit Ogg Vorbis, MP3, WAV or AIFF sound files.
* Cut, copy, splice or mix sounds together.
* Change the speed or pitch of a recording.
```
```


Question: Does anyone know of a good Command Prompt replacement?  I've tried bash/Cygwin, but that does not really meet my needs at work because it's too heavy.  I'd like a function-for-function identical wrapper on cmd.exe, but with highlighting, intellisense, and (critically) a tabbed interface.  Powershell is okay, but the interface is still lacking.

Answer:
Edited
: I've been using
ConEmu
(
http://conemu.github.io/
) for quite some time now. This one is a wrapper too, since it is not really possible to replace the Windows console without rewriting the whole command interpreter. Below the line is my original answer for an earlier alternative.
Not exactly a replacement (actually, it's a prettifying wrapper) but you might try
Console
(
http://sourceforge.net/projects/console/
)


Question: If I call os.stat() on a broken symlink, python throws an OSError exception. This makes it useful for finding them. However, there are a few other reasons that os.stat() might throw a similar exception. Is there a more precise way of detecting broken symlinks with Python under Linux?

Answer:
Can I mention testing for hardlinks without python? /bin/test has the FILE1 -ef FILE2 condition that is true when files share an inode.
Therefore, something like
```
find . -type f -exec test \{} -ef /path/to/file \; -print
```
works for hard link testing to a specific file.
Which brings me to reading
```
man test
```
and the mentions of
```
-L
```
and
```
-h
```
which both work on one file and return true if that file is a symbolic link, however that doesn't tell you if the target is missing.
I did find that
```
head -0 FILE1
```
would return an exit code of
```
0
```
if the file can be opened and a
```
1
```
if it cannot, which in the case of a symbolic link to a regular file works as a test for whether it's target can be read.


Question:
I'm trying to write a RegEx for a code generator (in C#) to determine a proper class or package name of an AS3 class.

I know that class names

must start with a letter (capital or otherwise)

any other digit can be alphanumeric

cannot have spaces

Is there anything else?

Answer:
Here are some more valid classes.
Actionscript 3 classes (and packages) must start with a letter, "_", or "$". They may also contain (but not start with) a number.
```
```
public class $Test {}
public class _Test {}
public class test {}
```
```


Question: What are your favorite (G)Vim plugins/scripts?

Answer:
Tim Pope
has some kickass plugins.  I love his
surround
plugin.


Question:
In Linux, what is the difference between /dev/ttyS0 and /dev/ttys0?

I know that the first is a serial port, but what about the second, with the small s?

Answer:
see this
For a pseudo terminal pair such as
  ptyp3 and ttyp3, the pty... is the
  master or controlling terminal and the
  tty... is the slave. There are only 16
  ttyp's: ttyp0-ttypf (f is a
  hexadecimal digit).
To get more
  pairs, the 3 letters q, r, s may be
  used instead of p
. For example the
  pair ttys8, ptys8 is a pseudo terminal
  pair. The master and slave are really
  the same "port" but the slave is used
  by the application program and the
  master is used by a network program
  (or the like) which supplies (and
  gets) data to/from the slave port.


Question: What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?

Answer:
I've had good success using
Mockito
.
When I tried learning about JMock and EasyMock, I found the learning curve to be a bit steep (though maybe that's just me).
I like Mockito because of its simple and clean syntax that I was able to grasp pretty quickly. The minimal syntax is designed to support the common cases very well, although the few times I needed to do something more complicated I found what I wanted was supported and easy to grasp.
Here's an (abridged) example from the Mockito homepage:
```
```
import static org.mockito.Mockito.*;

List mockedList = mock(List.class);
mockedList.clear();
verify(mockedList).clear();
```
```
It doesn't get much simpler than that.
The only major downside I can think of is that it won't mock static methods.


Question: What is the simplest way to install memcached on CentOS for someone new to the world of Linux?  What is the best way to enable it for Apache and PHP

Answer:
Unless Apache and PHP have some option to utilize memcached for internal workings (of which I am unaware of), you typically don't "enable" it for such apps.  Instead, you would get a
client library
to use memcached from within your application, then start up memcached on whatever servers you want to provide memory with, then just use the client library API to store and retrieve cached data across multiple servers.


Question:
What should i use to code Classic ASP under Linux. I have really tried to use Emacs and Vim but I don't have the time to learn them.

What i'm looking for is:

Syntax highlighting

Code Browser (Ctags)

Preferably som sort of code insight

Something like Ultra Edit or E-texteditor.

Answer:
I'm not sure what you're asking here, but if you are simply looking for a text-editor, my recommendations would be:
Console-based:
jed (simple, with a DOS Edit-like menubar, supports syntax-highlighing)
nano / pico (even simpler)
X-based:
Kate (KDE, syntax-highlighing)
Mousepad (like notepad)
SciTE (syntax-highlighing)
There are of course likely to be a gazillion other text-editors better than the ones listed above, but these are the ones I tend to use.


Question:
I'd like to gain better knowledge of operating system internals. Process management, memory management, and stuff like that.

I was thinking of learning by getting to know either linux or BSD kernel.

Which one kernel is better for learning purposes?

What's the best place to start?

Can you recommend any good books?

Answer:
Linux
Device Drivers
Linux Core Kernel Commentary
Operating Systems Design and Implementation
I had previously bought these books on recommendation for the same purpose but I never got to studying them myself so only take them as second-hand advice.


Question:
I'm currently building a Java app that could end up being run on many different platforms, but primarily variants of Solaris, Linux and Windows.

Has anyone been able to successfully extract information such as the current disk space used, CPU utilisation and memory used in the underlying OS? What about just what the Java app itself is consuming?

Preferrably I'd like to get this information without using JNI.

Answer:
I think the best method out there is to implement the
SIGAR API by Hyperic
.  It works for most of the major operating systems ( darn near anything modern ) and is very easy to work with.  The developer(s) are very responsive on their forum and mailing lists.  I also like that it is
GPL2
Apache licensed
.  They provide a ton of examples in Java too!
SIGAR == System Information, Gathering And Reporting tool.


Question: I want to use Powershell to write some utilities, leveraging our own .NET components to handle the actual work.  This is in place of writing a small console app to tie the calls together.  My question is where I would find a good source of documentation or tutorial material to help me fast track this?

Answer:
If you want to load an assembly into your PowerShell session, you can use reflection and load the assembly.
```
```
[void][System.Reflection.Assembly]::LoadFrom(PathToYourAssembly)
```
```
After you load your assembly, you can call static methods and create new instances of a class.
A good tutorial can be found
here
.
Both books mentioned by EBGreen are excellent.  The PowerShell Cookbook is very task oriented and PowerShell in Action is a great description of the language, its focus and useability.  PowerShell in Action is one of my favorite books. :)


Question:
I've seen news of John Resig's fast new selector engine named Sizzle pop up in quite a few places, but I don't know what a selector engine is, nor have any of the articles given an explanation of what it is.  I know Resig is the creator of jQuery, and that Sizzle is something in Javascript, but beyond that I don't know what it is. So, what is a selector engine?

Thanks!

Answer:
A selector engine is used to query a page's DOM for particular elements, based on some sort of query (usually CSS syntax or similar).
For example, this jQuery:
```
```
$('div')
```
```
Would search for and return all of the <div> elements on the page.  It uses jQuery's selector engine to do that.
Optimizing the selector engine is a big deal because almost every operation you perform with these frameworks is based on some sort of DOM query.


Question: I haven't been to enough of these "live" events to really determine which, if any, are worth the time / money.  Which ones do you attend and why?

Answer:
I used to belong to my local Linux User Group which I co-founded but I treated it more as a social event than anything else but obviously a social event full of geeks is still a great way to get a great debate going :)
Conventions and the like I've not got much out of other than being pestered by businesses who can offer me nothing that is apart from a bunch of Linux and Hacker ones where I've met loads of people who I consider friends offline, again great for the social aspect but pretty worthless to me in other respects.
That's not to say I never got any business out of attending various events it's just that treating them as social occasions meant any business that did come my way was a bonus so I never left an event feeling like it was a waste of time.


Question: I want to compare 2 arrays of objects in JavaScript code.  The objects have 8 total properties, but each object will not have a value for each, and the arrays are never going to be any larger than 8 items each, so maybe the brute force method of traversing each and then looking at the values of the 8 properties is the easiest way to do what I want to do, but before implementing, I wanted to see if anyone had a more elegant solution. Any thoughts?

Answer:
EDIT: You cannot overload operators in current, common browser-based implementations of JavaScript interpreters.
To answer the original question, one way you could do this, and mind you, this is a bit of a hack, simply
serialize the two arrays to JSON
and then compare the two JSON strings. That would simply tell you if the arrays are different, obviously you could do this to
each
of the objects within the arrays as well to see which ones were different.
Another option is to use a library which has some nice facilities for comparing objects - I use and recommend
MochiKit
.
EDIT:
The answer kamens gave
deserves consideration as well, since a single function to compare two given objects would be much smaller than any library to do what I suggest (although my suggestion would certainly work well enough).
Here is a naïve implemenation that may do just enough for you - be aware that there are potential problems with this implementation:
```
```
function objectsAreSame(x, y) {
   var objectsAreSame = true;
   for(var propertyName in x) {
      if(x[propertyName] !== y[propertyName]) {
         objectsAreSame = false;
         break;
      }
   }
   return objectsAreSame;
}
```
```
The assumption is that both objects have the same exact list of properties.
Oh, and it is probably obvious that, for better or worse, I belong to the only-one-return-point camp. :)


Question:
I need to know about Epoll On linux System.

Could you recommend manual or guides about epoll library?

need more detailed guides. it's better to have some examples.

help me. and Thank you for reading.

Answer:
Here's an introduction to Epoll, a pretty basic tutorial:
http://blog.kovyrin.net/2006/04/13/epoll-asynchronous-network-programming/
A more complete example can be found here:
https://banu.com/blog/2/how-to-use-epoll-a-complete-example-in-c/
Also,
the man pages


Question:
Is there a rake task for backing up the data in your database?

I already have my schema backed up, but I want to make a backup of the data. It's a small MySQL database.

Answer:
The below script is a simplified version taken from
eycap
, specifically from
this file
.
```
```
set :dbuser "user"
set :dbhost "host"
set :database "db"

namespace :db do
  desc "Get the database password from user"
  task :get_password do
    set(:dbpass) do
      Capistrano::CLI.ui.ask "Enter mysql password: "
    end
  end

  task :backup_name, :only => { :primary => true } do
    now = Time.now
    run "mkdir -p #{shared_path}/db_backups"
    backup_time = [now.year,now.month,now.day,now.hour,now.min,now.sec].join('-')
    set :backup_file, "#{shared_path}/db_backups/#{database}-snapshot-#{backup_time}.sql"
  end

  desc "Dump database to backup file"
  task :dump, :roles => :db, :only => {:primary => true} do
    backup_name
    run "mysqldump --add-drop-table -u #{dbuser} -h #{dbhost} -p#{dbpass} #{database} | bzip2 -c > #{backup_file}.bz2"
  end
end
```
```
Edit: Yeah, I guess I missed the point that you were looking for a rake task and not a capistrano task, but I don't have a rake one on hand, sorry.


Question:
My goal is to maintain a web file server separately from my main ASP.NET application server for better scalability. The web file server will store a lot of files downloaded by users.

So the question is: Is it worth to adopt FreeBSD + Apache + ZFS, or will good old IIS be сonvenient enough?

Answer:
I understand you will serve only static files. In this case, lightweight HTTP servers will give you a higher performance for a given machine. The following are well known:
Lighttpd
Thttpd
Nginx
Many more are listed on
Wikipedia
. There's a more recent
article
on IBM DeveloperWorks.


Question:
How do I calculate the distance between two points specified by latitude and longitude?

For clarification, I'd like the distance in kilometers; the points use the WGS84 system and I'd like to understand the relative accuracies of the approaches available.

Answer:
This
link
might be helpful to you, as it details the use of the
Haversine formula
to calculate the distance.
Excerpt:
This script [in Javascript] calculates great-circle distances between the two points –
  that is, the shortest distance over the earth’s surface – using the
  ‘Haversine’ formula.
```
```
function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
  var R = 6371; // Radius of the earth in km
  var dLat = deg2rad(lat2-lat1);  // deg2rad below
  var dLon = deg2rad(lon2-lon1);
  var a =
    Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
    Math.sin(dLon/2) * Math.sin(dLon/2)
    ;
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var d = R * c; // Distance in km
  return d;
}

function deg2rad(deg) {
  return deg * (Math.PI/180)
}
```
```


Question:
We often hear/read that one should avoid dynamic casting. I was wondering what would be 'good use' examples of it, according to you?

Edit:

Yes, I'm aware of that other thread: it is indeed when reading one of the first answers there that I asked my question!

Answer:
My current toy project uses dynamic_cast twice; once to work around the lack of multiple dispatch in C++ (it's a visitor-style system that could use multiple dispatch instead of the dynamic_casts), and once to special-case a specific subtype.
Both of these are acceptable, in my view, though the former at least stems from a language deficit.  I think this may be a common situation, in fact; most dynamic_casts (and a great many "design patterns" in general) are workarounds for specific language flaws rather than something that aim for.


Question: What do you think the future of GPU as a CPU initiatives like CUDA are? Do you think they are going to become mainstream and be the next adopted fad in the industry? Apple is building a new framework for using the GPU to do CPU tasks and there has been alot of success in the Nvidias CUDA project in the sciences. Would you suggest that a student commit time into this field?

Answer:
I think it's the right way to go.
Considering that
GPUs have been tapped to create cheap supercomputers
, it appears to be the natural evolution of things. With so much computing power and R&D already done for you, why not exploit the available technology?
So go ahead and do it. It will make for some cool research, as well as a legit reason to buy that high-end graphic card so you can play Crysis and Assassin's Creed on full graphic detail ;)


Question:
What Windows code editors allow the use of elastic tabstops, either natively or through a plugin?

I know about a gedit plugin, but it only works on Linux.

Answer:
I did quite a bit of googling trying to find this answer. There are plenty of people asking for it:
http://developers.slashdot.org/comments.pl?sid=414610&cid=21996944
http://www.arguingwithmyself.com/archives/75-the-biggest-feature-your-editor-is-missing
http://intype.info/blog/screencast-parser-in-editor/#comment-221
http://codewords.wordpress.com/2006/10/16/eclipses-achilles-heel/
just to name a few...
so I don't think one exists yet, sorry :(


Question:
In Eclipse 3.2.2 on Linux content assist is not finding classes within the same project. Upgrading above 3.2 is not an option as SWT is not available above 3.2 for Solaris.

I have seen suggestions to clean the workspace, reopen the workspace, run eclipse with the -clean command, none of which has worked.

Answer: Go to Java/Editor/Content Assist/Advanced in Preferences, and make sure that the correct proposal kinds are selected. Same kind of thing happened to me when I first moved to 3.4.


Question: My university is part of MSDNAA, so I downloaded it a while back, but I just got around to installing it. I guess part of it replaces FrontPage for web editing, and there appears to be a video editor and a vector graphics editor, but I don't think I've even scratched the surface of what it is and what it can do. Could someone enlighten me, especially since I haven't found an "Expression Studio for Dummies" type website.

Answer:
From
Wikipedia
:
Microsoft Expression Studio is a suite of design and media applications from Microsoft aimed at developers and designers. It consists of:
Microsoft Expression Web (code-named Quartz) - WYSIWYG website designer and HTML editor.
Microsoft Expression Blend (code-named Sparkle) - Visual user interface builder for Windows Presentation Foundation and Silverlight applications.
Microsoft Expression Design (code-named Acrylic) - Raster and vector graphics editor.
Microsoft Expression Media - Digital asset and media manager.
Microsoft Expression Encoder - VC-1 content professional encoder.
For web development Expression Web is useful. For XAML development, Blend and Design are useful.


Question: Let's say I'm creating a program in C that needs to use a tempfile. Creating an ad hoc tempfile in /tmp is probably not a good idea. Is there a function or OS call to supply me with a tempfile name so that I can begin to write and read from it?

Answer:
You can use the
```
mkstemp(3)
```
function for this purpose. Another alternative is the
```
tmpfile(3)
```
function.
Which one of them you choose depends on whether you want the file to be opened as a C library file stream (which
```
tmpfile
```
does), or a direct file descriptor (
```
mkstemp
```
). The
```
tmpfile
```
function also deletes the file automatically when you program finishes.
The advantage of using these functions is that they avoid race conditions between determining the unique filename and creating the file -- so that two programs won't try to create the same file at the same time, for example.
See the man pages for both functions for more details.


Question:
Can anyone recommend a good repository viewer for Git, similar to gitk, that works on Mac OS X Leopard? (I'm not saying gitk doesn't work)

Of course I would like a native Mac application, but as I haven't found any, what are the best options to gitk?

I know about gitview, but I'm looking forward to evaluate as many alternatives as possible.

http://sourceforge.net/projects/gitview

Answer:
There are a couple under development.
GitNub
Gitty
(404, dead project)
I don't know if there are any that have hit 1.0.


Question:
Has anyone ever set up Cruise Control to build an OS X Cocoa/Objective-C project?

If so, is there a preferred flavor of CruiseControl (CruiseControl.rb or just regular CruiseControl) that would be easier to do this with.

I currently have a Ruby rake file that has steps for doing building and running tests, and wanted to automate this process after doing a checkin.

Also, does CruiseControl have support for git?  I couldn't find anything on the website for this.

Answer:
Yes, you just run xcode builds via the command line (xcodebuild) which makes it simple to target from CC via an ant
```
<exec>
```
. I've been using just regular CC, not the ruby version and it works fine. Here's a barebones example:
```
```
<project name="cocoathing" default="build">
  <target name="build">
    <exec executable="xcodebuild" dir="CocoaThing" failonerror="true">
      <arg line="-target CocoaThing -buildstyle Deployment build" />
    </exec>
  </target>
</project>
```
```
More info on xcodebuild
And there does appear to be a standard git object
here
, but I don't use git so I can't tell you much more than that!


Question:
How can you get the version information from a .dll or .exe file in PowerShell?

I am specifically interested in File Version, though other version information (that is, Company, Language, Product Name, etc.) would be helpful as well.

Answer:
```
```
[System.Diagnostics.FileVersionInfo]::GetVersionInfo("Path\To\File.dll")
```
```


Question: Is there a good, native Mac tool to view Mercurial repositories, similar to gitnub for Git?

Answer:
You can use the one "built in",
```
hg view
```
. You'll need
```
TCL
```
installed though.
From the documentation:
The hgk Tcl script is a direct port of the gitk tool used with git. The hgk.py extension allows hgk to interact with mercurial in a git-like manner.
edit
@
Matthew
: yeah, that's why I linked to the documentation that explains it. You need to enable it in your .hgrc (like the
```
fetch
```
command), and TCL --as mentioned.


Question:
The HTML standard defines a clear separation of concerns between CSS (presentation) and HTML (semantics or structure).

Does anyone use a coding standards document for CSS and XHTML that has clauses which help to maintain this separation? What would be good clauses to include in such a coding standards document?

Answer:
We don't have a physical document we all adhere to where I work. There are a number of guidelines we try and keep in mind but there isn't really enough information to require a physcial document.
This article
sums them up these guidelines pretty well.  You may also consider formatting your
```
CSS
```
to make it easier to read.
Smashing Magazine
has a great article on this subject.


Question: I'm not sure whether I'm asking the question correctly, but I've been told SQL Server cannot run on a Novell server. Is this true? If yes, why not?

Answer:
You may have to be more specific about what a "novell server" is.  From what I understand, Novell servers run some form of Suse linux.  Sql Server is a windows only product.
My company, however, does have clients that run Novell networks, and we do run Sql Servers on their network.  But they're hosted on a win box...


Question: I'm new to SVN and I'd like to know what methods are available for backing up repositories in a Windows environment?

Answer:
I like to just copy the entire repo directory to my backup location.  That way, if something happens, you can just copy the directory back and be ready to go immediately.
Just make sure to preserve permissions, if needed.  Usually, this is only a concern on Linux machines.


Question:
I played with one of the early beta versions of PowerShell V1, but haven't used it since it went "gold". What is the best way to get started using PowerShell?

Which version of PowerShell should I be using (V1.0 vs 2.0 CTP's)? What are you using PowerShell for? Are there any tools that make using PowerShell easier (that is, development environments)?

Answer:
There are a number of PowerShell tools, for example,
PowerGUI
PowerShell Plus
(not free)
PowerShell in Action
is a well-regarded book.
And the Powershell team
has a blog
.


Question: Does anyone know of a powershell cmdlet out there for automating task scheduler in XP/2003?  If you've ever tried to work w/ schtasks you know it's pretty painful.

Answer:
You don't need PowerShell to automate the Task Scheduler, you can use the SCHTASKS command in XP.
According to
Wikipedia
, the Task Scheduler 2.0 (Vista and Server 2008) is accesible via COM.


Question:
When running my application I sometimes get an error about too many files open.

Running ulimit -a reports that the limit is 1024.  How do I increase the limit above 1024?

Edit
ulimit -n 2048 results in a permission error.

Answer:
You could always try doing a
```
ulimit -n 2048
```
.  This will only reset the limit for your current shell and the number you specify must not exceed the hard limit
Each operating system has a different hard limit setup in a configuration file.  For instance, the hard open file limit on Solaris can be set on boot from /etc/system.
```
```
set rlim_fd_max = 166384
set rlim_fd_cur = 8192
```
```
On OS X, this same data must be set in /etc/sysctl.conf.
```
```
kern.maxfilesperproc=166384
kern.maxfiles=8192
```
```
Under Linux, these settings are often in /etc/security/limits.conf.
There are two kinds of limits:
soft
limits are simply the currently enforced limits
hard
limits mark the maximum value which cannot be exceeded by setting a soft limit
Soft limits could be set by any user while hard limits are changeable only by root.
Limits are a property of a process. They are inherited when a child process is created so system-wide limits should be set during the system initialization in init scripts and user limits should be set during user login for example by using pam_limits.
There are often defaults set when the machine boots.  So, even though you may reset your ulimit in an individual shell, you may find that it resets back to the previous value on reboot.  You may want to grep your boot scripts for the existence ulimit commands if you want to change the default.


Question:
I have a directory with PDF files that I need to create an index for. It is a PHP page with a list of links:

<A HREF="path to file">filename</A>

The filenames can be complicated:

LVD 2-1133 - Ändring av dumpningslina (1984-11-20).pdf

What is the correct way to link to this file on a Linux/Apache server?

Is there a PHP function to do this conversion?

Answer:
urlencode()
should probably do what you want.
Edit
: urlencode() works fine on swedish characters.
```
```
<?php
        echo urlencode("åäö");
    ?>
```
```
converts to:
```
```
%E5%E4%F6
```
```


Question:
How, if you have a database per client of a web application instead of one database used by all clients, do you go about providing updates and enhancements to all databases efficiently?

How do you roll out changes to schema and code in such a scenario?

Answer:
bittorrent
?
There have been a few web-based versions already (
bitlet
,
w3btorrent
), and
Azureus
was built using java, so it's definitely possible.
Edit: @TonyB is it limited to port 80?


Question:
What is the best way to create fluid width/height rounded corners with jQuery?

That plugin doesn't keep the height the same.  I have a 10px high div that I want to round the corners on, when I use that script it adds about 10px onto whats there.

Answer:
```
```
$(this).corner();
```
```
See:
malsup.com/jquery/corner
and
github repository for future ref


Question:
What things should be kept most in mind when writing cross-platform applications in C? Targeted platforms: 32-bit Intel based PC, Mac, and Linux. I'm especially looking for the type of versatility that Jungle Disk has in their USB desktop edition ( http://www.jungledisk.com/desktop/download.aspx )

What are tips and "gotchas" for this type of development?

Answer:
Try to write as much as you can with POSIX. Mac and Linux support POSIX natively and Windows has a system that can run it (as far as I know - I've never actually used it). If your app is graphical, both Mac and Linux support X11 libraries (Linux natively, Mac through X11.app)  and there are numerous ways of getting X11 apps to run on Windows.
However, if you're looking for true multi-platform deployment, you should probably switch to a language like Java or Python that's capable of running the same program on multiple systems with little or no change.
Edit: I just downloaded the application and looked at the files. It does appear to have binaries for all 3 platforms in one directory. If your concern is in how to write apps that can be moved from machine to machine without losing settings, you should probably write all your configuration to a file in the same directory as the executable and not touch the Windows registry or create any dot directories in the home folder of the user that's running the program on Linux or Mac. And as far as creating a cross-distribution Linux binary, 32-bit POSIX/X11 would probably be the safest bet. I'm not sure what JungleDisk uses as I'm currently on a Mac.


Question:
I've been using git for some time now on Windows (with msysGit) and I like the idea of distributed source control. Just recently I've been looking at Mercurial (hg) and it looks interesting. However, I can't wrap my head around the differences between hg and git.

Has anyone made a side-by-side comparison between git and hg? I'm interested to know what differs hg and git without having to jump into a fanboy discussion.

Answer:
I'm currently in the process of migrating from SVN to a DVCS (while blogging about my findings, my first real blogging effort...), and I've done a bit of research (=googling). As far as I can see you can do most of the things with both packages. It seems like git has a few more or better implemented advanced features,
I do feel that the integration with windows is a bit better for mercurial, with TortoiseHg. I know there's Git Cheetah as well (I tried both), but the mercurial solution just feels more robust.
Seeing how they're both open-source (right?) I don't think either will be lacking important features. If something is important, people will ask for it, people will code it.
I think that for common practices, Git and Mercurial are more than sufficient. They both have big projects that use them (Git -> linux kernel, Mercurial -> Mozilla foundation projects, both among others of course), so I don't think either are really lacking something.
That being said, I am interested in what other people say about this, as it would make a great source for my blogging efforts ;-)


Question:
How do I get the id of my Java process?

I know there are several platform-dependent hacks, but I would prefer a more generic solution.

Answer:
There exists no platform-independent way that can be guaranteed to work in all jvm implementations.
```
ManagementFactory.getRuntimeMXBean().getName()
```
looks like the best (closest) solution, and typically includes the PID. It's short, and
probably
works in every implementation in wide use.
On linux+windows it returns a value like
```
"12345@hostname"
```
(
```
12345
```
being the process id). Beware though that
according to the docs
, there are no guarantees about this value:
Returns the name representing the running Java virtual machine. The
returned name string can be any arbitrary string and a Java virtual
machine implementation can choose to embed platform-specific useful
information in the returned name string. Each running virtual machine
could have a different name.
In Java 9
the new
process API
can be used:
```
```
long pid = ProcessHandle.current().pid();
```
```


Question: I have a list of more than 15 thousand latitude and longitude coordinates.  Given any X,Y coordinates, what is the fastest way to find the closest coordinates on the list?

Answer:
You will want to use a geometric construction called a
Voronoi diagram
. This divides up the plane into a number of areas, one for each point, that encompass all the points that are closest to each of your given points.
The code for the exact algorithms to create the Voronoi diagram and arrange the data structure lookups are too large to fit in this little edit box. :)
@Linor: That's essentially what you would do after creating a Voronoi diagram. But instead of making a rectangular grid, you can choose dividing lines that closely match the lines of the Voronoi diagram (this way you will get fewer areas that cross dividing lines). If you recursively divide your Voronoi diagram in half along the best dividing line for each subdiagram, you can then do a tree search for each point you want to look up. This requires a bit of work up front but saves time later. Each lookup would be on the order of log N where N is the number of points. 16 comparisons is a lot better than 15,000!


Question: I've created a few autorun script files on various USB devices that run bash scripts when they mount.  These scripts run "in the background", how do I get them to run in a terminal window? (Like the "Application in Terminal" gnome Launcher type.)

Answer:
Run them as a two stage process with your "autorun" script calling the second script in a new terminal eg
```
```
gnome-terminal -e top --title Testing
```
```
Would run the program "top" in a new gnome terminal window with the title "Testing" You can add additional arguments like setting the geometry to determine the size and location of the window checkout the man page for
gnome-terminal
and the "X" man page for more details


Question:
Suppose your git history looks like this:

1
2
3
4
5

1–5 are separate revisions. You need to remove 3 while still keeping 1, 2, 4 and 5. How can this be done?

Is there an efficient method when there are hundreds of revisions after the one to be deleted?

Answer:
To combine revision 3 and 4 into a single revision, you can use git rebase. If you want to remove the changes in revision 3, you need to use the edit command in the interactive rebase mode. If you want to combine the changes into a single revision, use squash.
I have successfully used this squash technique, but have never needed to remove a revision before. The git-rebase documentation under "Splitting commits" should hopefully give you enough of an idea to figure it out. (Or someone else might know).
From the
git documentation
:
Start it with the oldest commit you want to retain as-is:
```
git rebase -i <after-this-commit>
```
An editor will be fired up with all the commits in your current branch (ignoring merge commits), which come after the given commit. You can reorder the commits in this list to your heart's content, and you can remove them. The list looks more or less like this:
```
pick deadbee The oneline of this commit
pick fa1afe1 The oneline of the next commit
...
```
The oneline descriptions are purely for your pleasure; git-rebase will not look at them but at the commit names ("deadbee" and "fa1afe1" in this example), so do not delete or edit the names.
By replacing the command "pick" with the command "edit", you can tell git-rebase to stop after applying that commit, so that you can edit the files and/or the commit message, amend the commit, and continue rebasing.
If you want to fold two or more commits into one, replace the command "pick" with "squash" for the second and subsequent commit. If the commits had different authors, it will attribute the squashed commit to the author of the first commit.


Question:
I have a set of Berkeley DB files on my Linux file system that I'd like to examine.

What useful tools exist for getting a quick overview of the contents? I can write Perl scripts that use BDB modules for examining them, but I'm looking for some CLI utility to be able to take a look inside without having to start writing scripts.

Answer:
Check out the
db-utils
package. If you use apt, you can install it with the following:
```
apt-get install db-util
```
(or
```
apt-get install db4.8-util
```
or whatever version you have or prefer.)
Additional links:
http://rpmfind.net/linux/rpm2html/search.php?query=db-utils
https://packages.ubuntu.com/search?suite=default&section=all&arch=any&keywords=db-util&searchon=names
Man page of db4.4_dump


Question: Is there anything which can help with msmq monitoring? I'd like to get some event/monit when a message appears in queue and the same on leave.

Answer:
Check out the Windows Management Performance counters.
If you look in your Administrative Tools and find "Performance Counters", you will be able to dig through there and find detailed metrics on what is happening on each message queue. This can also work for remote servers.
Should you wish to create some sort of automation around the monitoring, check out the .NET libraries for reading these performance counters. There is a very rich and comprehensive API which should give you everything you need!


Question: Is there an easy way to tell if a ruby script is already running and then handle it appropriately?  For example:  I have a script called really_long_script.rb.  I have it cronned to run every 5 minutes.  When it runs, I want to see if the previous run is still running and then stop the execution of the second script.  Any ideas?

Answer:
In bash:
```
```
if ps aux | grep really_long_script.rb | grep -vq grep
then
    echo Script already running
else
    ruby really_long_script.rb
fi
```
```


Question: Specifically, what commands do I run from the terminal?

Answer:
Without a home directory
```
```
sudo useradd myuser
```
```
With home directory
```
```
sudo useradd -m myuser
```
```
Then set the password
```
```
sudo passwd myuser
```
```
Then set the shell
```
```
sudo usermod -s /bin/bash myuser
```
```


Question:
Is there a way to identify, from within a VM, that your code is running inside a VM?

I guess there are more or less easy ways to identify specific VM systems, especially if the VM has the provider's extensions installed (such as for VirtualBox or VMWare). But is there a general way to identify that you are not running directly on the CPU?

Answer:
In most cases, you shouldn't try to. You shouldn't care if someone is running your code in a VM, except in a few specific cases.
If you need to, in Linux the most common way is to look at
```
/sys/devices/virtual/dmi/id/product_name
```
, which will list the name of the laptop/mainboard on most real systems, and the hypervisor on most virtual systems.
```
dmidecode | grep Product
```
is another common method, but I think that requires root access.


Question:
Is there a maximum number of inodes in a single directory?

I have a directory of over 2 million files and can't get the ls command to work against that directory. So now I'm wondering if I've exceeded a limit on inodes in Linux. Is there a limit before a 2^64 numerical limit?

Answer:
Can you get a real count of the number of files?  Does it fall very near a 2^n boundry?  Could you simply be running out of RAM to hold all the file names?
I know that in windows at least file system performance would drop dramatically as the number of files in the folder went up, but I thought that linux didn't suffer from this issue, at least if you were using a command prompt.  God help you if you try to get something like nautilus to open a folder with that many files.
I'm also wondering where these files come from.  Are you able to calculate file names programmatically?  If that's the case, you might be able to write a small program to sort them into a number of sub-folders.  Often listing the name of a specific file will grant you access where trying to look up the name will fail.  For example, I have a folder in windows with about 85,000 files where this works.
If this technique is successful, you might try finding a way to make this sort permanent, even if it's just running this small program as a cron job.  It'll work especially well if you can sort the files by date somewhere.


Question:
I know I can do most of this by hacking Trac and using Git hooks, but I was wondering if someone has / knows of something ready.

Commenting on (and closing) tickets from commit messages would be nice, specially if the diff appears inline with the comment/closing remark.

sha1 hashes should be auto-linked to gitweb/cigt/custom git browser.

I tried the GitPlugin for Trac, but the code browser was soo slow... any alternatives?

Answer:
Redmine
can do some of what you're asking for.  Integration works in one direction, you must
reference issues in commit messages
, and then this data will be available in redmine.
The data is then available in two views.  The bug display will include a list of matched commits.  The repository display will link commits to bug display pages.
Redmine keeps a local (bare) repository for each project.  This can be the primary repo or a remote mirror.  On updates, redmine parses the commit messages and updates an internal cross reference table of change_set,issue.
If the redmine repository is only used as a mirror, it will need to be updated.  Updates can happen via cron or via external hook.  We use a
redmine github plugin
and a github post-receive hook to keep redmine in sync with a primary github repository.
It works, but it is still a bit clumsy.


Question:
I'm doing a fair bit of work in Ruby recently, and using

 ruby script/console

Is absolutely critical. However, I'm really disappointed with the default Windows console in Vista, especially in that there's a really annoying bug where moving the cursor back when at the bottom of the screen irregularly causes it to jump back. Anyone have a decent console app they use in Windows?

Answer:
Powershell
Windows PowerShell is Microsoft's task automation framework, consisting of a command-line shell and associated scripting language built on top of, and integrated with the .NET Framework. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems.


Question:
I'm attracted to the neatness that a single file database provides. What driver/connector library is out there to connect and use SQLite with Java.

I've discovered a wrapper library, http://www.ch-werner.de/javasqlite, but are there other more prominent projects available?

Answer:
The
wiki
lists some more wrappers:
Java wrapper (around a SWIG interface):
http://tk-software.home.comcast.net/
A good tutorial to use JDBC driver for SQLite. (it works at least !)
http://www.ci.uchicago.edu/wiki/bin/view/VDS/VDSDevelopment/UsingSQLite
Cross-platform JDBC driver which uses embedded native SQLite libraries on Windows, Linux, OS X, and falls back to pure Java implementation on other OSes:
https://github.com/xerial/sqlite-jdbc
(formerly
zentus
)
Another Java - SWIG wrapper. It only works on Win32.
http://rodolfo_3.tripod.com/index.html
sqlite-java-shell: 100% pure Java port of the sqlite3 commandline shell built with NestedVM. (This is not a JDBC driver).
SQLite JDBC Driver for Mysaifu JVM: SQLite JDBC Driver for Mysaifu JVM and SQLite JNI Library for Windows (x86) and Linux (i386/PowerPC).


Question: Is there any library (or even better, web service) available which can convert from a latitude/longitude into a time zone?

Answer:
Project dead :-/
These look pretty promising-
Archive link:
https://web.archive.org/web/20150503145203/http://www.earthtools.org/webservices.htm


Question:
I need to convert latitude/longitude coordinates into Easting/Northing coordinates in the Alberta 10 TM Projection.

The 10 TM projection is similar to UTM, but it is a custom projection for the province of Alberta, Canada.  I think (with some effort) I could code it myself but would rather not reinvent the wheel if it's been done already.

Answer:
Grab
PROJ Cartographic Projections library
- open source library.
Suggested parameters for 10TM:
+proj=tmerc +lon_0=-115 +k_0=0.9992 +x_0=500000 +datum=NAD27
According to
this post
you may need to:
change the ellps to GRS80 if your 10TM
data is referenced to the NAD83 datum
(instead of NAD27/clrk66).  You may
also need to change the false northing
(y_0) to be -5000000 if your 10TM
coordinates for Alberta are less than
5,000,000 (an AltaLIS "standard").
I should mention that proj.4 is
the library
to get for any kind of geographic coordinate system transformation.  There's pretty much no transformation it can't do.
I also recommend reading
Map Projections-A Working Manual (Paperback) by John Snyder
if you are into these kinds of things.. it's a classic. :) (fixed the link)


Question:
Does anyone have experience using the URL Rewrite Module (see here)?

Can it be used to do reverse proxy?

Answer:
You're going to want to take a look at memcached. It's what a lot of huge (and well-scaled) sites used to handle problems just like this. If you have a few spare servers, you can easily set them up to keep most of your data in memory.
http://en.wikipedia.org/wiki/Memcached
http://www.danga.com/memcached/
http://www.socialtext.net/memcached/


Question: What is the best way to multi-thread in the C language? I want something that is very efficient and not a CPU hog. Thanks.

Answer:
If you're on a UNIX-based platform (Linux or Mac OS X) your best option is
POSIX threads
. They're the standard cross-platform way to multithread in a POSIX environment. They can also be used in Windows, but there are probably better (more native) solutions for that platform.


Question:
I've got a utility that outputs a list of files required by a game.  How can I run that utility within a C program and grab its output so I can act on it within the same program?

UPDATE: Good call on the lack of information.  The utility spits out a series of strings, and this is supposed to be portable across Mac/Windows/Linux.  Please note, I'm looking for a programmatic way to execute the utility and retain its output (which goes to stdout).

Answer:
For simple problems in Unix-ish environments try
```
popen()
```
.
From the man page:
The popen() function opens a process by creating a pipe, forking and invoking the shell.
If you use the read mode this is exactly what you asked for. I don't know if it is implemented in Windows.
For more complicated problems you want to look up inter-process communication.


Question: I need to diff two log files but ignore the time stamp part of each line (the first 12 characters to be exact).  Is there a good tool, or a clever awk command, that could help me out?

Answer:
@EbGreen said
I would just take the log files and strip the timestamps off the start of each line then save the file out to different files. Then diff those files.
That's probably the best bet, unless your diffing tool has special powers.
For example, you could
```
```
cut -b13- file1 > trimmed_file1
cut -b13- file2 > trimmed_file2
diff trimmed_file1 trimmed_file2
```
```
See @toolkit's response for an optimization that makes this a one-liner and obviates the need for extra files. If your shell supports it. Bash 3.2.39 at least seems to...


Question: I want to make an etag that matches what Apache produces.  How does apache create it's etags?

Answer:
Apache uses the standard format of inode-filesize-mtime.  The only caveat to this is that the mtime must be epoch time and padded with zeros so it is 16 digits.  Here is how to do it in PHP:
```
```
$fs = stat($file);
header("Etag: ".sprintf('"%x-%x-%s"', $fs['ino'], $fs['size'],base_convert(str_pad($fs['mtime'],16,"0"),10,16)));
```
```


Question: Does anyone know of any existing packages or libraries that can be used to build a calendar in a django app?

Answer:
A quick google search reveals
django-gencal
, which looks like exactly what you need.  It would also be worth looking at the snippets under the calendar tag on Django Snippets at
http://www.djangosnippets.org/tags/calendar/
.


Question:
Let's compile a list of tips.

(Understandably there will be some subjectivity involved, but some pointers would be useful to someone overwhelmed by tackling a large project within the Flash framework.)

Answer:
These are just scattered thoughts on organization for projects being worked on mostly with the Flash IDE.
First, I highly recommend using source control, like Subversion, CVS, or Git.
Organization of filesystem folder structure is subjective, but I generally have a "src" folder for all my source FLAs and AS class files, and a "deploy" or "bin" folder for compiled files. The src folder would contain class package files, with class packages organized in reverse domain style (e.g. - com.codehinting.projectname.context ). Modify the publish path of your FLA to publish to the deploy folder by tracing back up using the "../" path segment, for as many levels as needed to trace back from the nesting in the src folder.
Also, I typically place third-party libraries (that are pretty well "baked") in a separate location and then modify the global classpath in the Flash IDE to point to this location.
Two extremely handy plugins for the Flash IDE are Create Basic Layers and Library Generator, which quickly create your skeleton layer and library folder structure - saves time versus manually creating layers and folders.


Question: On Fedora Core 7, I'm writing some code that relies on ARG_MAX.  However, even if I #include <limits.h>, the constant is still not defined.  My investigations show that it's present in <sys/linux/limits.h>, but this is supposed to be portable across Win32/Mac/Linux, so directly including it isn't an option.  What's going on here?

Answer:
The reason it's not in limits.h is that it's not a quantity giving the limits of the value range of an integral type based on bit width on the current architecture.  That's the role assigned to limits.h by the ISO standard.
The value in which you're interested is not hardware-bound in practice and can vary from platform to platform and perhaps system build to system build.
The correct thing to do is to call
```
sysconf
```
and ask it for "ARG_MAX" or "_POSIX_ARG_MAX".  I
think
that's the POSIX-compliant solution anyway.
Acc. to my documentation, you include one or both of unistd.h or limits.h based on what values you're requesting.
One other point:  many implementations of the exec family of functions return E2BIG or a similar value if you try to call them with an oversized environment.  This is one of the defined conditions under which exec can actually return.


Question:
I'm looking at working on a project which uses C#.NET (sitting on a windows box) as the primary language and PostgreSQL as the backend database (backend is sitting on a linux box).  I've heard that ODBC.NET allows for easy integration of these two components.

Has anyone had experience actually setting C# and PostgreSQL up to work together?  If so, do you have any suggestions about how to go about it, issues you've found, etc.?

Answer:
I'm working with C# and Postgres using
Npgsql2
component, and they work fast, I recommend you.
You can download from
https://github.com/npgsql/Npgsql/releases
Note:
If you want an application that works with any database you can use the
DbProviderFactory
class and make your queries using
IDbConnection
,
IDbCommand
,
IDataReader
and/or
IDbTransaction
interfaces.


Question: I am writing a C program in Linux.  Commands like execv() require a path in the form of a C string.  Is there a command that will return the current path in the form of a C-style string?

Answer:
getcwd()
:
SYNOPSIS
```
```
#include <unistd.h>

char *getcwd(char *buf, size_t size);
```
```
DESCRIPTION
The
getcwd()
function shall place an absolute pathname of the current working directory in the array pointed to by
buf, and return buf
. The pathname copied to the array shall contain no components that are symbolic links. The
size
argument is the size in bytes of the character array pointed to by the
buf
argument. If
buf
is a null pointer, the behavior of getcwd() is unspecified.
RETURN VALUE
Upon successful completion,
getcwd()
shall return the
buf
argument. Otherwise,
getcwd()
shall return a null pointer and set
errno
to indicate the error. The contents of the array pointed to by
buf
are then undefined....


Question:
If I was going to start an open source project using Python what version should I use to ensure that the vast majority of users can use it on their system?

I'm the kind of person who quickly jumps to the next version (which I'll do when Python 3 comes out) but many people may be more conservative if their current version seems to be working fine. What version would hit the sweet spot but still allow me to enjoy the newest and coolest language enhancements?

Answer:
I've not seen a system with less than 2.3 installed for some time.  Mostly 2.4+ is installed by default for most OS I use now.  2.3 is just on an older Solaris machine.  Linux distros tend to have 2.4+, as does OS X.
IIRC, 2.4 has a lot of the features 2.5 does, but usable only with
```
```
from __future__ import *
```
```


Question:
I'm trying to debug a deadlock in a multi-threaded Python application after it has locked up.  Is there a way to attach a debugger to inspect the state of the process?

Edit: I'm attempting this on Linux, but it would be great if there were a cross-platform solution.  It's Python after all :)

Answer:
What platform are you attempting this on? Most debuggers allow you to attach to a running process by using the process id.
You can either output the process id via logging or using something like Task Manager.
Once that is achieved it will be possible to inspect individual threads and their call stacks.
EDIT: I don't have any experience with GNU Debugger (GDB), which is cross platform, however I found this
link
and it may start you on the right path. It explains how to add debug symbols (handy for reading stack traces) and how to instruct gdb to attach to a running python process.


Question: I've heard that creating a new process on a Windows box is more expensive than on Linux.  Is this true?  Can somebody explain the technical reasons for why it's more expensive and provide any historical reasons for the design decisions behind those reasons?

Answer:
Unix has a 'fork' system call which 'splits' the current process into two, and gives you a second process that is identical to the first (modulo the return from the fork call).  Since the address space of the new process is already up and running this is should be cheaper than calling 'CreateProcess' in Windows and having it load the exe image, associated dlls, etc.
In the fork case the OS can use 'copy-on-write' semantics for the memory pages associated with both new processes to ensure that each one gets their own copy of the pages they subsequently modify.


Question: On linux, it's possible to create a tun interface using a tun driver which provides a "network interface psuedo-device" that can be treated as a regular network interface.  Is there a way to do this programmatically on windows?  Is there a way to do this without writing my own driver?

Answer:
You can do this on XP with the
Microsoft Loopback Adapter
which is a driver for a virtual network card.
On newer Windows version:
Installing the Microsoft Loopback Adapter in Windows 8 and Windows Server 2012


Question:
I want to generate a thumbnail preview of videos in Java. I'm mostly JMF and video manipulation alienated.

Is there an easy way to do it?

What about codecs? Will I have to deal with it?

Any video type is suported? (including Quicktime)

Answer:
Are you sure that JMF is right for you?  Unfortunately, it is not in particularly good shape.  Unless you are already committed to JMF, you very well may want to investigate alternatives. Wikipedia has a decent overview at
en.wikipedia.org/wiki/Java_Media_Framework
Many JMF developers have complained that it
supports few codecs and formats in modern use
. Its all-Java version, for example, cannot play MPEG-2, MPEG-4, Windows Media, RealMedia, most QuickTime movies, Flash content newer than Flash 2, and
needs a plug-in to play the ubiquitous MP3 format
.  While the performance packs offer the ability to use the native platform's media library, they're only offered for Linux, Solaris and Windows. Furthermore,
Windows-based JMF developers can unwittingly think JMF provides support for more formats than it does
, and be surprised when their application is unable to play those formats on other platforms.
Another knock against JMF is Sun's seeming abandonment of it. The
API has not been touched since 1999
, and the last news item on JMF's home page was posted in November 2004.
While JMF is built for extensibility,
there are few such third-party extensions
.
Furthermore,
editing functionality in JMF is effectively non-existent
, which makes a wide range of potential applications impractical.


Question: How do I find out which process is listening on a TCP or UDP port on Windows?

Answer:
PowerShell
TCP
```
```
Get-Process -Id (Get-NetTCPConnection -LocalPort YourPortNumberHere).OwningProcess
```
```
UDP
```
```
Get-Process -Id (Get-NetUDPEndpoint -LocalPort YourPortNumberHere).OwningProcess
```
```
cmd
```
```
netstat -a -b
```
```
(Add
-n
to stop it trying to resolve hostnames, which will make it a lot faster.)
Note Dane's recommendation for
TCPView
. It looks very useful!
-a
Displays all connections and listening ports.
-b
Displays the executable involved in creating each connection or listening port. In some cases well-known executables host multiple independent components, and in these cases the sequence of components involved in creating the connection or listening port is displayed. In this case the executable name is in [] at the bottom, on top is the component it called, and so forth until TCP/IP was reached. Note that this option can be time-consuming and will fail unless you have sufficient permissions.
-n
Displays addresses and port numbers in numerical form.
-o
Displays the owning process ID associated with each connection.


Question: Simply, are there any Java Developer specific Linux distros?

Answer:
The distro which is most developer friendly, in my opinion, is
Gentoo
. Since you compile everything from scratch, you choose exactly what makes up your system. Java can be installed very easily, so you could potentially just have a
window environment
and Java installed (aside from the standard tool chain.)


Question:
I really enjoy Chrome, and the sheer exercise of helping a port would boost my knowledge-base.

Where do I start?

What are the fundamental similarities and differences between the code which will operated under Windows and Linux?

What skills and software do I need?

Note:

The official website is Visual Studio oriented!

Netbeans or Eclipse are my only options.

I will not pay Microsoft to help an Open Source project.

Answer:
Read this article on Chrome and Open Source on Linux:
http://arstechnica.com/journals/linux.ars/2008/09/02/google-unveils-chrome-source-code-and-linux-port
The Google V8 JavaScript Engine is also open source and available here if you want to contribute;
http://code.google.com/p/v8/
If you want to contribute on Chronium, here are the instructions:
http://dev.chromium.org/developers/contributing-code
Chromium
is an open-source browser
  project that aims to build a safer,
  faster, and more stable way for all
  Internet users to experience the web.
  This site contains design documents,
  architecture overviews, testing
  information, and more to help you
  learn to build and work with the
  Chromium source code.
Here is how you can get started:
http://dev.chromium.org/developers/how-tos/getting-started
EDIT: Two more questions was added to the original question.
Building on Linux requires the following software:
Subversion >= 1.4
pkg-config >= 0.20
Python >= 2.4
Perl >= 5.x
gcc/g++ >= 4.2
bison >= 2.3
flex >= 2.5.34
gperf >= 3.0.3
libnss3-dev >= 3.12
On Ubuntu 8.04, you can fetch all of the above as follows:
```
```
$ sudo apt-get install subversion pkg-config python perl g++ bison flex gperf libnss3-dev
```
```
Note
: There is no working
  Chromium-based browser on Linux.
  Although many Chromium submodules
  build under Linux and a few unit tests
  pass, all that runs is a command-line
  "all tests pass" executable.


Question:
I know PHP scripts don't actually compile until they are run. However, say I want to create a small simple program and compile it to a binary without requiring the PHP binary. How could I do this?

I've seen a few IDE's out there that would do this, but either they are all for windows or the Linux versions don't actually build properly.

What I would like is something like py2exe that does it in the script itself.

Answer:
There is this:
http://www.bambalam.se/bamcompile/
but that compiles to Windows bytecode.  There are a few others, but all I have seen will compile for windows only.
Few More:
http://www.nusphere.com/products/phpdock.htm
Edit: I almost forgot if your looking to make it work on linux without regard for windows you can just add
```
```
#!/usr/bin/php
```
```
to the top of the script and you should be able to run it from the command line.  Don't forget to chmod +x the file first.


Question:
I'm looking for the basic loop like:

for(int i = 0; i < MAX; i++) {
  doSomething(i);
}

but for Bash.

Answer:
From
this site
:
```
```
for i in $(seq 1 10);
do
    echo $i
done
```
```


Question:
Imagine a DOS style .cmd file which is used to launch interdependent windowed applications in the right order.

Example:

1) Launch a server application by calling an exe with parameters.

2) Wait for the server to become initialized (or a fixed amount of time).

3) Launch client application by calling an exe with parameters.

What is the simplest way of accomplishing this kind of batch job in PowerShell?

Answer:
To wait 10 seconds between launching the applications, try
```
```
launch-server-application serverparam1 serverparam2 ...
Start-Sleep -s 10
launch-client-application clientparam1 clientparam2 clientparam3 ...
```
```
If you want to create a script and have the arguments passed in, create a file called runlinkedapps.ps1 (or whatever) with these contents:
```
```
launch-server-application $args[0] $args[1]
Start-Sleep -s 10
launch-client-application $args[2] $args[3] $args[4]
```
```
Or however you choose to distribute the server and client parameters on the line you use to run runlinkedapps.ps1. If you want, you could even pass in the delay here, instead of hardcoding
```
10
```
.
Remember, your .ps1 file need to be on your Path, or you'll have to specify its location when you run it. (Oh, and I've assumed that launch-server-application and launch-client-application are on your Path - if not, you'll need to specify the full path to them as well.)


Question:
I have a filename in a format like:

system-source-yyyymmdd.dat

I'd like to be able to parse out the different bits of the filename using the "-" as a delimiter.

Answer:
Use the
```
cut
```
command.
e.g.
```
```
echo "system-source-yyyymmdd.dat" | cut -f1 -d'-'
```
```
will extract the first bit.
Change the value of the
```
-f
```
parameter to get the appropriate parts.
Here's a guide on the
Cut
command.


Question: Which files should I include in .gitignore when using Git in conjunction with Xcode?

Answer:
Based on
this guide for Mercurial
my .gitignore includes:
```
```
.DS_Store
*.swp
*~.nib

build/

*.pbxuser
*.perspective
*.perspectivev3
```
```
I've also chosen to include:
```
```
*.mode1v3
*.mode2v3
```
```
which, according to
this Apple mailing list post
, are "user-specific project settings".
And for Xcode 4:
```
```
xcuserdata
```
```


Question: I have been looking at the new Objective-J / Cappuccino javascript framework from 280North.  They provide plug-ins for SubEthaEdit and TextMate to handle syntax highlighting, but I primarily use vi.  Does anyone know of a way to get Objective-J syntax highlighting in vi, or a good way to convert whatever format the other two editors use?

Answer:
If regular javascript syntax highlighting is good enough, you can map that to .j files by adding something like this to your .vimrc file:
```
```
augroup objective-j
   au! BufRead,BufNewFile *.j set filetype=objective-j
   au! Syntax objective-j source /usr/share/vim/vim71/syntax/javascript.vim
   augroup END
```
```
I haven't tried this exact code, but did something similar when mapping C# syntax to .vala files on my Linux machine. (NOTE: The javascript.vim file might be located somewhere else on your computer.) You could of course make a objective-j.vim file based on that javascript.vim syntax definition instead of using it as it is.


Question: What tools are available to monitor graphics card memory usage in linux?

Answer:
If you just need to know it for 3D graphics development purposes, you may want to look into something like
gDEBugger
or, if you only care about NVIDIA cards, you can try
NVIDIA PerfHUD
.  I have not used them myself, but I would expect them to track such information.


Question: I need a way to determine the space remaining on a disk volume using python on linux, Windows and OS X. I'm currently parsing the output of the various system calls (df, dir) to accomplish this - is there a better way?

Answer:
The
os.statvfs()
function is a better way to get that information for Unix-like platforms (including OS X). The Python documentation says "Availability: Unix" but it's worth checking whether it works on Windows too in your build of Python (ie. the docs might not be up to date).
Otherwise, you can use the
pywin32
library to directly call the
GetDiskFreeSpaceEx
function.


Question:
Does anyone know of any good library that abstracts the problem of path manipulation in a nice way? I'd like to be able to combine and parse paths with arbitrary separators ('/' or ':' for example) without reinventing the wheel.

It's a shame that System.IO.Path isn't more reusable.

Thanks

Answer:
System.IO.Path.Combine will work great for many different types of paths:
http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx
System.IO.Path.Combine uses the current platform standard separators to combine paths. That means on Windows it uses "\" and on unix/linux (mono) it uses "/". Can you give some samples of what paths you are trying to combine and on what platform?


Question: We are working with an oracle database in which the person that set it up is "long gone" and thus do not know the sysdba password, but need it. We have root access to the box (its on linux). Is there any way to recover or change the sys passwords?

Answer:
Have you tried logging into Linux as your installed Oracle user then
```
```
sqlplus "/ as sysdba"
```
```
When you log in you'll be able to change your password.
```
```
alter user sys identified by <new password>;
```
```
Good luck :)


Question: How do I discard changes in my working copy that are not in the index?

Answer:
For all
unstaged
files in current working directory use:
```
```
git restore .
```
```
For a specific file use:
```
```
git restore path/to/file/to/revert
```
```
That together with
```
git switch
```
replaces the overloaded
```
git checkout
```
(
see here
), and thus removes the argument disambiguation.
If a file has both staged and unstaged changes, only the unstaged changes shown in
```
git diff
```
are reverted. Changes shown in
```
git diff --staged
```
stay intact.
Before Git 2.23
For all unstaged files in current working directory:
```
```
git checkout -- .
```
```
For a specific file:
```
```
git checkout -- path/to/file/to/revert
```
```
```
--
```
here to remove ambiguity (this is known as
argument disambiguation
).


Question:
I'm having trouble writing a regular expression that matches valid IPv6 addresses, including those in their compressed form (with :: or leading zeros omitted from each byte pair).

Can someone suggest a regular expression that would fulfill the requirement?

I'm considering expanding each byte pair and matching the result with a simpler regex.

Answer:
From "
IPv6 regex
":
```
```
(\A([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,6}\Z)|
(\A([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5}\Z)|
(\A([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4}\Z)|
(\A([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3}\Z)|
(\A([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2}\Z)|
(\A([0-9a-f]{1,4}:){1,6}(:[0-9a-f]{1,4}){1,1}\Z)|
(\A(([0-9a-f]{1,4}:){1,7}|:):\Z)|
(\A:(:[0-9a-f]{1,4}){1,7}\Z)|
(\A((([0-9a-f]{1,4}:){6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})\Z)|
(\A(([0-9a-f]{1,4}:){5}[0-9a-f]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})\Z)|
(\A([0-9a-f]{1,4}:){5}:[0-9a-f]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|
(\A([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|
(\A([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,3}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|
(\A([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,2}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|
(\A([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,1}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|
(\A(([0-9a-f]{1,4}:){1,5}|:):(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)|
(\A:(:[0-9a-f]{1,4}){1,5}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\Z)
```
```


Question:
This is probably a complex solution.

I am looking for a simple operator like ">>", but for prepending.

I am afraid it does not exist. I'll have to do something like

 mv myfile tmp
 cat myheader tmp > myfile

Anything smarter?

Answer:
This still uses a temp file, but at least it is on one line:
```
```
echo "text" | cat - yourfile > /tmp/out && mv /tmp/out yourfile
```
```
Credit:
BASH: Prepend A Text / Lines To a File


Question:
Is there a way to have Linux read ahead when cloning a disk?  I use the program named "dd" to clone disks.  The last time I did this it seemed as though the OS was reading then writing but never at the same time.  Ideally, the destination disk would be constantly writing without waiting that's of course if the source disk can keep up.

UPDATE: I normally choose a large block size when cloning (ex. 16M or 32MB).

Answer:
Maybe you can use two processes
```
```
dd if=indevfile | dd of=outdevfile
```
```
I'll assume you can set the other dd options as it suits you.
This has some overhead but should allow asynchrony between reading
one disk and writing the other.


Question:
Does any one know how do I get the current open windows or process of a local machine using Java?

What I'm trying to do is: list the current open task, windows or process open, like in  Windows Taskmanager, but using a multi-platform approach - using only Java if it's possible.

Answer:
The only way I can think of doing it is by invoking a command line application that does the job for you and then screenscraping the output (like Linux's ps and Window's tasklist).
Unfortunately, that'll mean you'll have to write some parsing routines to read the data from both.
```
```
Process proc = Runtime.getRuntime().exec ("tasklist.exe");
InputStream procOutput = proc.getInputStream ();
if (0 == proc.waitFor ()) {
    // TODO scan the procOutput for your data
}
```
```


Question:
One thing I really miss about Java is the tool support.  FindBugs, Checkstyle and PMD made for a holy trinity of code quality metrics and automatic bug checking.

Is there anything that will check for simple bugs and / or style violations of Ruby code?  Bonus points if I can adapt it for frameworks such as Rails so that Rails idioms are adhered to.

Answer:
Dust
looks like it can help you find unused and useless code, which seems like it sort-of fits what you're after.
I'm not aware of any other such tools.
This problem is vastly harder to address in ruby than it is in java - you'll note that all those java tools brand themselves as using 'static analysis' of the code.
Static analysis of ruby code often isn't possible, because there isn't anything static that you can analyze (methods often get created at runtime and so on)
At any rate, some of these things are unneeded in ruby because the language builds them in.
For example, you don't need a coding standard to enforce that your classes are all
```
NamedLikeThis
```
because the code won't work if they aren't.
P.S. I
have
to add the standard disclaimer that those kind of tools can often be a bit of a red herring. You can spend all day making your code adhere to what the tool thinks it should be, and end up with more bugs than you started with.
IMHO the best solution is to write your code fluently so you can read it more easily. No amount of static analysis is going to be as good as a human reading code which clearly states what it is meant to do. Being able to do this is where ruby is light-years ahead of many other languages. I personally would recommend you aim your efforts at learning how to write more fluently, and educating your team about such things, than spending time on static analysis.


Question:
How often should you use git-gc?

The manual page simply says:

Users are encouraged to run this task on a regular basis within each repository to maintain good disk space utilization and good operating performance.

Are there some commands to get some object counts to find out whether it's time to gc?

Answer:
It depends mostly on how much the repository is used.  With one user checking in once a day and a branch/merge/etc operation once a week you probably don't need to run it more than once a year.
With several dozen developers working on several dozen projects each checking in 2-3 times a day, you might want to run it nightly.
It won't hurt to run it more frequently than needed, though.
What I'd do is run it now, then a week from now take a measurement of disk utilization, run it again, and measure disk utilization again.  If it drops 5% in size, then run it once a week.  If it drops more, then run it more frequently.  If it drops less, then run it less frequently.


Question:
What is the best way, using Bash, to rename files in the form:

(foo1, foo2, ..., foo1300, ..., fooN)

With zero-padded file names:

(foo00001, foo00002, ..., foo01300, ..., fooN)

Answer:
The following will do it:
```
```
for ((i=1; i<=N; i++)) ; do mv foo$i `printf foo%05d $i` ; done
```
```
EDIT:
changed to use ((i=1,...)), thanks
mweerden
!


Question:
If you were to write an GUI application that runs locally and calls a webservice, to be cross platform, can you do it with .Net, what tools would you recommend?

I was considering Java as it would be relatively easy to pick up due to its C# similarity and then I could use the JVM.

Answer:
You should get familiar with the
Mono project
and
MonoDevelop
; the express purpose of those projects is to allow building and running .NET code on a variety of platforms, including Windows, Linux, and Mac OSX.
Since the Mono is a re-implementation of .NET, it always lags a little behind Microsoft.NET, but they've got good coverage of .NET 2.0 and some .NET 3.x features. Note that Mono executes .NET binaries, so as long as your program features are supported by Mono, you can take an application EXE you complied on Windows and run it on Linux/Mono without recompiling.


Question:
EditPad Lite has a nice feature (CTRL-E, CTRL-I) which inserts a time stamp e.g. "2008-09-11 10:34:53" into your code.

What is the best way to get this functionality in Vim?

(I am using Vim 6.1 on a Linux server via SSH. In the current situation a number of us share a login so I don't want to create abbreviations in the home directory if there is another built-in way to get a timestamp.)

Answer:
http://kenno.wordpress.com/2006/08/03/vim-tip-insert-time-stamp/
Tried it out, it works on my mac:
```
```
:r! date
```
```
produces:
```
```
Thu Sep 11 10:47:30 CEST 2008
```
```
This:
```
```
:r! date "+\%Y-\%m-\%d \%H:\%M:\%S"
```
```
produces:
```
```
2008-09-11 10:50:56
```
```


Question: I'm interested in grabbing the EPG data from DVB-T streams. Does anyone know of any C libraries or an alternative means of getting the data?

Answer:
tv_grab_dvb can do this. See the
subversion repository
for sources.
tv_grab_dvb is made to work with the stream grabbed from the DVB-T card using
dvbtools
on Linux, but it may be portable to other platforms - I think it just works with the raw data from the stream.


Question: I've been trying to convert SVG images to PNG using C#, without having to write too much code. Can anyone recommend a library or example code for doing this?

Answer:
You can call the command-line version of inkscape to do this:
http://harriyott.com/2008/05/converting-svg-images-to-png-in-c.aspx
Also there is a C# SVG rendering engine, primarily designed to allow SVG files to be used on the web on codeplex that might suit your needs if that is your problem:
Original Project
http://www.codeplex.com/svg
Fork with fixes and more activity:
(added 7/2013)
https://github.com/vvvv/SVG


Question: How does the open-source/free software community develop drivers for products that offer no documentation?

Answer:
Usually by reverse engineering the code. There might be legal issues in some countries, though.
Reverse Engineering
Reverse engineering Windows USB device drivers for the purpose of
creating compatible device drivers for Linux
Nvidia cracks down on third party driver development


Question: What command checks if a directory exists or not within a Bash shell script?

Answer:
To check if a directory exists:
```
```
if [ -d "$DIRECTORY" ]; then
  echo "$DIRECTORY does exist."
fi
```
```
To check if a directory does not exist:
```
```
if [ ! -d "$DIRECTORY" ]; then
  echo "$DIRECTORY does not exist."
fi
```
```
However, as
Jon Ericson
points out, subsequent commands may not work as intended if you do not take into account that a symbolic link to a directory will also pass this check.
E.g. running this:
```
```
ln -s "$ACTUAL_DIR" "$SYMLINK"
if [ -d "$SYMLINK" ]; then
  rmdir "$SYMLINK"
fi
```
```
Will produce the error message:
```
```
rmdir: failed to remove `symlink': Not a directory
```
```
So symbolic links may have to be treated differently, if subsequent commands expect directories:
```
```
if [ -d "$LINK_OR_DIR" ]; then
  if [ -L "$LINK_OR_DIR" ]; then
    # It is a symlink!
    # Symbolic link specific commands go here.
    rm "$LINK_OR_DIR"
  else
    # It's a directory!
    # Directory command goes here.
    rmdir "$LINK_OR_DIR"
  fi
fi
```
```
Take particular note of the double-quotes used to wrap the variables. The reason for this is explained by 8jean
in another answer
.
If the variables contain spaces or other unusual characters it will probably cause the script to fail.


Question:
How do I get the path of the directory in which a Bash script is located, inside that script?

I want to use a Bash script as a launcher for another application. I want to change the working directory to the one where the Bash script is located, so I can operate on the files in that directory, like so:

$ ./application

Answer:
Use
```
dirname "$0"
```
:
```
```
#!/usr/bin/env bash

echo "The script you are running has basename $( basename -- "$0"; ), dirname $( dirname -- "$0"; )";
echo "The present working directory is $( pwd; )";
```
```
Using
```
pwd
```
alone will not work if you are not running the script from the directory it is contained in.
```
```
[matt@server1 ~]$ pwd
/home/matt
[matt@server1 ~]$ ./test2.sh
The script you are running has basename test2.sh, dirname .
The present working directory is /home/matt
[matt@server1 ~]$ cd /tmp
[matt@server1 tmp]$ ~/test2.sh
The script you are running has basename test2.sh, dirname /home/matt
The present working directory is /tmp
```
```


Question:
I want to make a copy of an ActiveRecord object, changing a single field in the process (in addition to the id).  What is the simplest way to accomplish this?

I realize I could create a new record, and then iterate over each of the fields copying the data field-by-field - but I figured there must be an easier way to do this.

Perhaps something like this:

 new_record = Record.copy(:id)

Answer:
To get a copy, use the
dup
(or clone for < rails 3.1+) method:
```
```
#rails >= 3.1
new_record = old_record.dup

# rails < 3.1
new_record = old_record.clone
```
```
Then you can change whichever fields you want.
ActiveRecord overrides the built-in Object#clone
to give you a new (not saved to the DB) record with an unassigned ID.
Note that it does not copy associations, so you'll have to do this manually if you need to.
Rails 3.1 clone is a shallow copy, use dup instead...


Question:
In all the Git tutorials I've read they say that you can do:

git init
git add .
git commit

When I do that I get a big text file opened up. None of the tutorials seem to address this, so I don't know what to do with the file or what to put in it if anything.

Answer:
The
```
git commit
```
command will open up the editor specified in the
```
EDITOR
```
environment variable so you can enter a commit comment.  On a Linux or BSD system, this should be vi by default, although any editor should work.
Just enter your comments and save the file.


Question:
What is the best way for me to determine a controller variable's value during execution?

For example, is there a way I can insert a break in the code, and cause the value of the variable to be output to the screen (or the log)?

Answer:
Yes. The easiest way is to raise the value as a string. Like so:
```
raise @foo.to_s
```
Or, you can install the debugger (
```
gem install ruby-debug
```
), and then start the development server with the
```
--debugger
```
flag. Then, in your code, call the
```
debugger
```
instruction.
Inside the debugger prompt, you have many commands, including
```
p
```
to print the value of a variable.
Update:
here's
a bit more about ruby-debug
.


Question:
I was always attracted to the world of kernel hacking and embedded systems.

Has anyone got good tutorials (+easily available hardware) on starting to mess with such stuff?

Something like kits for writing drivers etc, which come with good documentation and are affordable?

Thanks!

Answer:
For embedded Linux hacking, simple Linksys WRT54G router that you can buy everywhere is a development platform on its own
http://en.wikipedia.org/wiki/Linksys_WRT54G_series
:
The WRT54G is notable for being the first consumer-level network device that had its firmware source code released to satisfy the obligations of the GNU GPL. This allows programmers to modify the firmware to change or add functionality to the device. Several third-party firmware projects provide the public with enhanced firmware for the WRT54G.
I've tried installing
OpenWrt
and
DD-WRT
firmware on it.  You can check those out as a starting point for hacking on a low-cost platform.


Question:
I'd like to redirect the stdout of process proc1 to two processes proc2 and proc3:

         proc2 -> stdout
       /
 proc1
       \
         proc3 -> stdout

I tried

 proc1 | (proc2 & proc3)

but it doesn't seem to work, i.e.

 echo 123 | (tr 1 a & tr 1 b)

writes

 b23

to stdout instead of

 a23
 b23

Answer:
Editor's note
:
-
```
>(…)
```
is a
process substitution
that is a
nonstandard shell feature
of
some
POSIX-compatible shells:
```
bash
```
,
```
ksh
```
,
```
zsh
```
.
- This answer accidentally sends the output process substitution's output through the pipeline
too
:
```
echo 123 | tee >(tr 1 a) | tr 1 b
```
.
- Output from the process substitutions will be unpredictably interleaved, and, except in
```
zsh
```
, the pipeline may terminate before the commands inside
```
>(…)
```
do.
In unix (or on a mac), use the
```
tee
```
command
:
```
```
$ echo 123 | tee >(tr 1 a) >(tr 1 b) >/dev/null
b23
a23
```
```
Usually you would use
```
tee
```
to redirect output to multiple files, but using >(...) you can
redirect to another process. So, in general,
```
```
$ proc1 | tee >(proc2) ... >(procN-1) >(procN) >/dev/null
```
```
will do what you want.
Under windows, I don't think the built-in shell has an equivalent. Microsoft's
Windows PowerShell
has a
```
tee
```
command though.


Question:
I'd like to script, preferably in rake, the following actions into a single command:

Get the version of my local git repository.

Git pull the latest code.

Git diff from the version I extracted in step #1 to what is now in my local repository.

In other words, I want to get the latest code form the central repository and immediately generate a diff of what's changed since the last time I pulled.

Answer:
This is very similar to a question I asked about
how to get changes on a branch in git
. Note that the behaviour of git diff vs. git log is inconsistently different when using two dots vs. three dots. But, for your application you can use:
```
```
git fetch
git diff ...origin
```
```
After that, a
```
git pull
```
will merge the changes into your HEAD.


Question: What are the best file permission settings for PHP scripts? Any suggestions on ways to figure out the minimum required permissions?

Answer:
This is very similar to a question I asked about
how to get changes on a branch in git
. Note that the behaviour of git diff vs. git log is inconsistently different when using two dots vs. three dots. But, for your application you can use:
```
```
git fetch
git diff ...origin
```
```
After that, a
```
git pull
```
will merge the changes into your HEAD.


Question:
We have a simple [spring-hibernate] application (console app) where in we have set the classpath in manifest file of the executable JAR file. And the app connects to the database using jTDS JDBC Driver, Everything works as expected on Windows machine and JDK 1.6, but on Linux, the app is unable to find the driver,
We are running the program using java -jar MainClassName.

Any suggestions why this might be happening is greatly appreciated.

Answer:
Honestly it sounds like bad CLASSPATH. One thing I suggest to start debugging this problem is copying the jtds package to same path as your main packages/classes and see if it works. This way you can assure the Classpath manifest is or isn't the problem. The Spring/Hibernate relies on the lib directory, so it will always be on classpath because it's main structure. Use the lib directory also to test.
Hope this guidelines will help. Also send more information, like paths, classpath and manifest files.


Question: How do I delete untracked local files from the current working tree?

Answer:
git-clean
is what you are looking for. It is used to remove untracked files from the working tree.


Question:
I'm working on a cross platform application in Java which currently works nicely on Windows, Linux and MacOS X. I'm trying to work out a nice way to do detection (and handling) of 'crashes'. Is there an easy, cross-platform way to detect 'crashes' in Java and to do something in response?

I guess by 'crashes' I mean uncaught exceptions. However the code does use some JNI so it'd be nice to be able to catch crashes from bad JNI code, but I have a feeling that's JVM specific.

Answer:
For handling uncaught exceptions you can provide a new ThreadGroup which provides an implementation of ThreadGroup.uncaughtException(...). You can then catch any uncaught exceptions and handle them appropriately (e.g. send a crash log home).
I can't help you on the JNI front, there's probably a way using a native wrapper executable before calling the JVM, but that executable is going to need to know about all the possible JVMs it could be calling and how the indicate crashes and where crash logs are placed etc.


Question: I use the VS2008 command prompt for builds, TFS access etc. and the cygwin prompt for grep, vi and unix-like tools. Is there any way I can 'import' the vcvars32.bat functionality into the cygwin environment so I can call "tfs checkout" from cygwin itself?

Answer:
According to
this page
you need to:
"Depending on your preference, you can either add the variables required for compilation direct to your environment, or use the vcvars32.bat script to set them for you. Note you have to compile from a cygwin bash shell, to use vcvars32, first run a DOS shell, then run vcvars32.bat, then run cygwin.bat from the directory where you installed cygwin. You can speed this up by adding the directory containgin vcvars32 (somewhere under \Microsoft Visual Studio\VC98\bin) and the directory containing cygwin.bat to your path."


Question:
How do I ask PowerShell where something is?

For instance, "which notepad" and it returns the directory where the notepad.exe is run from according to the current paths.

Answer:
This seems to do what you want (I found it on
http://huddledmasses.org/powershell-find-path/
):
```
```
Function Find-Path($Path, [switch]$All = $false, [Microsoft.PowerShell.Commands.TestPathType]$type = "Any")
## You could comment out the function stuff and use it as a script instead, with this line:
#param($Path, [switch]$All = $false, [Microsoft.PowerShell.Commands.TestPathType]$type = "Any")
   if($(Test-Path $Path -Type $type)) {
      return $path
   } else {
      [string[]]$paths = @($pwd);
      $paths += "$pwd;$env:path".split(";")

      $paths = Join-Path $paths $(Split-Path $Path -leaf) | ? { Test-Path $_ -Type $type }
      if($paths.Length -gt 0) {
         if($All) {
            return $paths;
         } else {
            return $paths[0]
         }
      }
   }
   throw "Couldn't find a matching path of type $type"
}
Set-Alias find Find-Path
```
```


Question:
I have a rather large file (150 million lines of 10 chars). I need to split it in 150 files of 2 million lines, with each output line being alternatively the first 5 characters or the last 5 characters of the source line.
I could do this in Perl rather quickly, but I was wondering if there was an easy solution using bash.
Any ideas?

Answer:
Homework?  :-)
I would think that a simple pipe with sed (to split each line into two) and split (to split things up into multiple files) would be enough.
The man command is your friend.
Added after confirmation that it is not homework:
How about
```
```
sed 's/\(.....\)\(.....\)/\1\n\2/' input_file | split -l 2000000 - out-prefix-
```
```
?