Skip to content

Instantly share code, notes, and snippets.

@CrBoy
CrBoy / tower.py
Created June 23, 2012 07:33
Colored Tower with animation
import time
import os
for t in range(60)*100:
for i in range(1,10,2)+range(7,0,-2):
print ' '*t+'\033[1;5;3'+str(t%5+1)+';4'+str(t%5+1)+'m'+'*'*i+'\033[m'
time.sleep(0.1)
os.system('clear')
@CrBoy
CrBoy / README
Created June 22, 2012 04:53
Experiment of finding the difference of indirect variable access using eval() and locals() in Python
Use strace and ltrace to trace the runtime behavior
@CrBoy
CrBoy / paint_text.py
Created March 25, 2012 04:47 — forked from dannvix/paint_text.py
Paint text on given image with PIL
#!/usr/bin/env python
#-*- encoding: utf8
# sudo easy_install PIL
import Image
import ImageFont
import ImageDraw
import sys
import os
@CrBoy
CrBoy / trap_test1.sh
Created March 17, 2012 14:46
The `trap' in bash scripts
#!/bin/bash
trap "echo TRAP!!; exit" SIGTERM SIGINT SIGHUP
for (( i=0; i<5; i=i+1 ))
do
echo $i
sleep 1
done
@CrBoy
CrBoy / exec.c
Created December 28, 2011 04:52
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
void redirect_to(char *filename)
{
int fd = open(filename, O_RDWR | O_CREAT, 0666);
@CrBoy
CrBoy / list_quick_sort.h
Created November 30, 2011 05:04 — forked from baiyanhuang/list_quick_sort.h
quick sort of single linked list
#pragma once
#include <utility>
//
// Quick sort for single linked list
//
// Template arguments:
// T: node's pointer type
// Next: function/functor to get next node
// Compare: functor to compare 2 arguments
//
@CrBoy
CrBoy / MyClass.h
Created November 8, 2011 09:08
A strange problem about BOOST_CLASS_EXPORT
#ifndef MYCLASS_H
#define MYCLASS_H
#include <boost/serialization/export.hpp>
#include <boost/serialization/vector.hpp>
using namespace std;
class A
{
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
using namespace std;
using namespace boost::lambda;
int main(int argc, const char *argv[])
@CrBoy
CrBoy / zip.cpp
Created November 3, 2011 18:17
A simple implementation like Python's zip
#include <list>
#include <utility>
#include <iostream>
using namespace std;
template<class T1, class T2>
list< pair<T1,T2> > zip(const list<T1>& container1, const list<T2>& container2)
{
list< pair<T1,T2> > result;
@CrBoy
CrBoy / cutility.c
Created November 3, 2011 11:03
Cutility - Command-line drawing utility
#include "cutility.h"
void gotoxy(int x, int y)
{
static HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
COORD coord={x, y};
SetConsoleCursorPosition(hConsole, coord);
}
void setcolor(const char *fg, const char *bg)