Skip to content

Instantly share code, notes, and snippets.

@khajavi
khajavi / enum.c
Created May 24, 2013 11:28
enum example in c
#include <stdio.h>
enum {
SHOW,
HIDE,
COVERED,
};
int main() {
printf("%d", SHOW);
@khajavi
khajavi / redirectio.py
Created May 22, 2013 12:22
redirect io to file
#!/usr/bin/env python3
import sys
orig_stdout = sys.stdout
f = open('out.txt', 'w')
sys.stdout = f
alphabets = "qwertyuiopasdfghjklzxcvbnm"
codes = [ x + y + z for x in alphabets for y in alphabets for z in alphabets ]
@khajavi
khajavi / word_occurrence_counter.py
Created May 19, 2013 20:35
example of dictionary data type
import string
import sys
words = {}
strip = string.whitespace + string.punctuation + string.digits + "\"'"
for filename in sys.argv[1:]:
for line in open( filename ):
for word in line.lower().split():
word = word.strip( strip )
if len( word ) > 2:
// Written by Pioz.
// Compile with: gcc -o autoclick autoclick.c -lX11
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
// Simulate mouse click
void
click (Display *display, int button)
// g++ font_path_list.cxx $(pkg-config x11 --libs --cflags)
#include <X11/Xlib.h>
#include <cassert>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <iterator>
@khajavi
khajavi / paste.cc
Created April 20, 2013 11:06 — forked from bmeck/paste.cc
// CODE
/* test.cc
* Compile with: g++ `pkg-config --cflags --libs x11` test.cc -o test
* Run with: ./test
*/
#include <stdio.h>//printf
#include <string.h>//strlen
#include <stdlib.h>//atexit
#include <X11/Xlib.h>
#include <iostream>
#include <unistd.h>
int main(void) {
Display* dpy = XOpenDisplay(0);
int scr = XDefaultScreen(dpy);
Window root_window = XRootWindow(dpy, scr);
int height = DisplayHeight(dpy, scr);
@khajavi
khajavi / window_with_a_little_black_sqaure_in_it.c
Created April 20, 2013 10:50
Hello World by Xlib library
/*
* Simple Xlib application drawing a box in a window.
* gcc input.c -o output -lX11
* Adopted from http://en.wikipedia.org/wiki/Xlib
*/
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@khajavi
khajavi / gdk_initialization_and_exit.c
Created April 20, 2013 09:48
GDK initialization and exit
#include <gdk/gdk.h>
int main( int argc, char* argv[] ) {
gdk_init( &argc, &argv );
gdk_exit( 0 );
return 0;
}
/*
* Print entire HTML text after processed JavaScript
*
* build:
* FLAGS=`pkg-config --cflags --libs gtk+-x11-2.0 glib-2.0 webkit-1.0`
* gcc -Wall $FLAGS getbodytext.c -o getbodytext
*
* usage:
* /usr/bin/xvfb-run ./getbodytext test.html
*