Skip to content

Instantly share code, notes, and snippets.

#include <glib.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <glib/gprintf.h>
#include <string.h>
/*
*
* Colorpicker. That's all.
*
@khajavi
khajavi / my_first_gdk_app.c
Created April 20, 2013 08:11
My first app in GDK library
/*
* Adopted from http://james.id.au/tech/doc/gdk/
* gcc -o my_first_gdk_app.bin my_first_gdk_app.c `pkg-config gtk+-2.0 --cflags --libs`
* The GDK headers. Very important.
*/
#include <gdk/gdk.h>
/* Convenient way to suck in all the glib stuff.
*/
#include <glib.h>
@khajavi
khajavi / pdfviewer.c
Created April 20, 2013 05:47
pdf viewer by poppler library
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <cairo.h>
#include <poppler.h>
/* gcc `pkg-config --cflags --libs gtk+-2.0 poppler-glib` -o pdfviewer pdfviewer.c */
@khajavi
khajavi / create_png_image.c
Last active December 16, 2015 08:48
Hello World in Cairo
/*
* adopted from http://zetcode.com/gfx/cairo/cairobackends/
*/
#include <cairo.h>
int main() {
cairo_surface_t* surface;
cairo_t* cr;
@khajavi
khajavi / startWith.c
Created April 4, 2013 13:02
startWith( prefix, String )
bool startWith( const char* prefix, const char* string ) {
return strncmp( prefix, string, strlen( prefix ) ) == 0;
}
@khajavi
khajavi / append.c
Last active December 15, 2015 19:19
c-string append (concat)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const char* append( const char* str1, const char* str2 ) {
const size_t str1_length = strlen( str1 );
const size_t str2_length = strlen( str2 );
const size_t total_length = str1_length + str2_length;
char *const str_buff =(char*) malloc( total_length + 1 );
@khajavi
khajavi / .vimrc
Last active December 15, 2015 13:49
set t_Co=256
colo moria
set tabstop=2
set shiftwidth=2
set completeopt=menu
filetype plugin on
syntax on
set number
nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR>
@khajavi
khajavi / Spelling.java
Created March 16, 2013 11:55
Spell Corrector
import java.io.*;
import java.util.*;
import java.util.regex.*;
class Spelling {
// برای اینکه سرعت الگوریتم تصحیح‌کنندهٔ املایی بالا رود نیاز به جست‌وجو با سرعت بالا در یک بانک اطلاعاتی وسیعی داریم. به همین دلیل از جدول هش استفاده می‌کنیم:
private final HashMap<String, Integer> nWords = new HashMap<String, Integer>();
// کلاس Spelling یک ساختمان دادهٔ جدید برای جمع‌آوری لغات آماده می‌کند.
@khajavi
khajavi / adapter.cpp
Created February 26, 2013 06:35 — forked from pazdera/adapter.cpp
/*
* Example of `adapter' design pattern
* Copyright (C) 2011 Radek Pazdera
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
@khajavi
khajavi / builder.cpp
Created February 10, 2013 11:28 — forked from pazdera/builder.cpp
/*
* Example of `builder' design pattern.
* Copyright (C) 2011 Radek Pazdera
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,