Skip to content

Instantly share code, notes, and snippets.

testing gist.io.
@khakimov
khakimov / gist:3307549
Created August 9, 2012 19:58
Wierd version of unfollow
require 'nokogiri'
require 'json'
require 'open-uri'
require 'oauth'
# Exchange your oauth_token and oauth_token_secret for an AccessToken instance.
# https://dev.twitter.com/apps here
def prepare_access_token(oauth_token, oauth_token_secret)
consumer = OAuth::Consumer.new("Consumer key", "Consumer secret",
{ :site => "http://api.twitter.com",
@khakimov
khakimov / gist:3328576
Created August 12, 2012 01:08
convert integer into a binary character representation
#include <stdio.h>
void itob(unsigned int n);
int main()
{
itob(100);
return 0;
}
@khakimov
khakimov / gist:3329057
Created August 12, 2012 02:18
decimal to hexadecimal
/*
Exercise 3-4 K&R.
To convert a decimal number x to hexadecimal, we can repeatedly divide x by 16,
giving a quotient q and a remainder r, such that x = q * 16 + r.
*/
#include <stdio.h>
@khakimov
khakimov / gist:3539792
Created August 30, 2012 20:15
Rocket science
#include <stdio.h>
double recip(int denom)
{
return 1.0/(double) denom;
}
void do_nothing() {}
int main(int argc, char const *argv[])
@khakimov
khakimov / gist:3558086
Created August 31, 2012 19:49
Matrix Effect in you terminal
echo -e "\e[1;40m" ; clear ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) ;sleep 0.05; done|awk '{ letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()"; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'
@khakimov
khakimov / gist:3831753
Created October 4, 2012 06:17
pass struct by reference
#include <stdio.h>
struct randal {
int x;
int y;
char z;
};
void func1(int test, struct randal *p)
{
@khakimov
khakimov / gist:3913629
Created October 18, 2012 17:40
using mutex [pthreads]
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
double *a;
double *b;
double sum;
int veclen;
@khakimov
khakimov / gist:3914044
Created October 18, 2012 18:47
posix thread
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void *thread(void *arg);
int main()
{
pthread_t tid;
pthread_create(&tid, NULL, thread, NULL);
@khakimov
khakimov / gist:4029456
Created November 7, 2012 03:41
libevent http client
#include <sys/types.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <stdlib.h>
#include <err.h>
#include <event.h>
#include <evhttp.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>