Skip to content

Instantly share code, notes, and snippets.

// 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)
@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:
@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 / 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 / simple_cairo.c
Created May 26, 2013 21:05
Simple gtk base caro example
#include <gtk/gtk.h>
#include <cairo.h>
static gboolean
on_draw_event( GtkWidget* widget,
cairo_t *cr,
gpointer user_data ) {
cairo_set_source_rgb( cr, 0.3, 0.5, 0.8 );
cairo_rectangle( cr, 100, 100, 50, 50 );
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
struct A {
bool a:1;
bool b:1;
bool c:1;
bool d:1;
};
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
int main() {
union
{
uint8_t c[4];
@khajavi
khajavi / bitfield.c
Created May 29, 2013 03:15
example of bitfield in c programming.
#include <stdio.h>
struct Bitfield {
int a:4;
unsigned int b:4;
} bit;
struct Boolean {
unsigned int a:1;
} boolean;
@khajavi
khajavi / floating_point_ieee.c
Created May 29, 2013 04:25
Converting floating-point number to IEEE754 representation by using union and struct in c.
#include <stdio.h>
/*
* See also : http://class.ece.iastate.edu/arun/CprE281_F05/ieee754/ie5.html
*/
union FloatingPointIEEE754 {
struct {
unsigned int mantissa : 23;
unsigned int exponent : 8;
unsigned int sign : 1;
@khajavi
khajavi / convert_float_to_ieee754.c
Created May 29, 2013 10:42
example of conveting float numbers to ieee 754 in single and double precison format.
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
/*
* See also : http://class.ece.iastate.edu/arun/CprE281_F05/ieee754/ie5.html
*/
union FloatingPointSinglePrecisionIEEE754 {
struct {