Jan 10, 2013

Compiling C from stdin

allheads.h:
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <gsl/gsl_rng.h>
Paste this onto your command line, or add it to your .bashrc, .zshrc, or wherever applicable:
go_libs="-lm"
go_flags="-g -Wall -include allheads.h -O3"
alias go_c="c99 -xc '-' $go_libs $go_flags"
And now we can use a here document to paste short C programs onto the command line:
go_c << '---'
int main(){printf("Hello from the command line.\n");}
---
# and then run:
./a.out

Python shell command

Execute code:
python -c "print 'hi.'"
# or
echo "print 'hi.'" | python '-'
# equal to
echo "print 'hi.'" | python -- -
Execute multiline code:
python '-' <<"EOF"
lines=2
print "\nThis script is %i lines long.\n" %(lines,)
EOF
Using json.tool to validate and pretty-print:
curl https://app01.nutshell.com/api/v1/json | python -m json.tool

Jan 8, 2013

Python to Javascript converters

https://github.com/buchuki/pyjaco

http://pyjs.org/
pyjamas/bin/pyjscompile -o output.js source.py
--strict: this preserves maximum Python semantic compatibility (up to the point of including a copy of the source file to provide tracebacks exactly like Python does);
-O: this tries to balance Python compatibility with speed: turns off function argument checking, attribute checking, bound methods, and using classes for numbers.
--stupid-mode: produces the minimal possible code, at the cost of switching Python semantics with JS semantics.

Jan 7, 2013

Head First C - David Griffiths

Exit status of last program
echo $?

&x - location in memory of x variable

You can also call sizeof for a data type, such as sizeof(int).

You can declare a char pointer as const char * to prevent the code from using it to modify a string.

man strstr
info coreutils 'printf'

Q: But what if I want to pass negative numbers as command-line arguments like set_temperature -c -4? Won’t it think that the 4 is an option, not an argument?
A: In order to avoid ambiguity, you can split your main arguments from the options using --. So you would write set_temperature -c -- -4. getopt() will stop reading options when it sees the --, so the rest of the line will be read as simple arguments.

(./bermuda | ./geo2json) < spooky.csv > output.json

If you genuinely want to share variables, you should declare them in your header file and prefix them with the keyword extern: 
extern int passcode;

make takes away a lot of the pain of compiling files. But if you find that even it is not automatic enough, take a look at a tool called autoconf

The make tool can do far, far more than we have space to discuss here. To find out more about make and what it can do for you, visit the GNU Make Manual

Remember: when you're assigning struct variables, you are telling the computer to copy data.

If you use the typedef command, you can normally skip giving the struct a proper name. But in a recursive structure, you need to include a pointer to the same type. C syntax won't let you use the typedef alias, so you need to give the struct a proper name. That's why the struct here is called struct island.

The nm command lists the names that are stored inside the archive.
nm /usr/lib/libruby1.8-static.a

When you bind a socket to a port, the operating system will prevent anything else from rebinding to it for the next 30 seconds or so, and that includes the program that bound the port in the first place. Use reuse option (p. 477) 

MUT-EX = MUTually EXclusive.

The make tool knows quite a lot about C compilation, and it can use implicit rules to build files without you telling it exactly how.  For example, if you have a file called fred.c, you can compile it without a makefile by typing:
> make fred
cc fred.c -o fred

Purchase at Amazon

https://bitbucket.org/st1tch/head-first-c

Author repository: https://github.com/dogriffiths/HeadFirstC

Generate safe bug reports

…
from django.views.decorators.debug import sensitive_post_parameters

@sensitive_post_parameters("password")
def login_view(request):
    …
POST:<QueryDict: {u'csrfmiddlewaretoken': [u'F3d71EHWECfavaeK4H7nUTzLwgY07AHT'],
                  u'password': [u'********************'],
                  u'email': [u'aruseni.magiku@gmail.com']}>
…
from django.views.decorators.debug import sensitive_variables

@sensitive_variables("payment_card_id")
def process_payment(request):
    …
http://habrahabr.ru/post/164935/

Jan 3, 2013

JavaScript profiling, Console

console.dir(obj);

console.time("t1")
....
console.timeEnd("t1")

console.profile("p1")
...
console.profileEnd("p1")

console.trace()

console.count("my_fun_count")