Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
struct A {
int a;
char b;
};
struct A foo() {
struct A a;
a.a = 3;
@ifduyue
ifduyue / 0_reuse_code.js
Created May 24, 2014 11:30
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
#!/bin/bash
# this will install everything as root, so take that into account before you run it
set -eu
# need cmake, python development headers, ZLib and OpenSSL
sudo apt-get install -y cmake python2.7-dev zlib1g-dev libssl-dev
root=`pwd`
#coding: utf8
import re
import time
import datetime
import dateutil.tz
# Remember offset is in seconds west of UTC, but the timezone is in
# minutes east of UTC.
cat - << EOWARNING
WARNING: This script will fil up your left over disk space.
DO NOT RUN THIS WHEN YOUR VIRTUAL HD IS RAW!!!!!!
You should NOT do this on a running system.
This is purely for making vagrant boxes damn small.
Press Ctrl+C within the next 10 seconds if you want to abort!!
#!/usr/bin/perl
use 5.008;
use strict;
use Memoize;
# usage:
# git-large-files 500k
# git-large-files 0.5m
# git-large-files 5b
@ifduyue
ifduyue / gist:1183166
Created August 31, 2011 09:29
httplib example: publish a fanfou status
def setcookie2cookie(setcookie):
cookies = setcookie.split("\n")
result = []
for ck in cookies:
frags = ck.split(";")
i = frags[0].index("=")
name = frags[0][:i]
value = frags[0][i+1:]
#name = name.replace("+", " ")
if name.strip():
@ifduyue
ifduyue / gist:1376898
Created November 18, 2011 16:11
mb_code.py
def mb_code(string, coding="utf-8"):
if isinstance(string, unicode):
return string.encode(coding)
for c in ('utf-8', 'gb2312', 'gbk', 'gb18030', 'big5'):
try:
return string.decode(c).encode(coding)
except: pass
return string
@ifduyue
ifduyue / benchmark.py
Created December 12, 2011 07:40
benchmark pylru, lrucache, lru
import lru
import lrucache
import pylru
import random
import sys
size = int(sys.argv[1])
data = []
range_ = int(sys.argv[2])
for i in xrange(int(sys.argv[3])):