Skip to content

Instantly share code, notes, and snippets.

View iveney's full-sized avatar
🏠
Working from home

Ivan Xiao iveney

🏠
Working from home
View GitHub Profile
@iveney
iveney / enumeration usage example.cpp
Created March 28, 2011 01:42
enumeration usage example
enum label{A,B,C,D,E,N}; // N is exactly the size
char * desc="ABCDE"
vector<int> v(N);
// do sth.
cout << desc[A] << "'s value is " << v[A] << endl;
@iveney
iveney / test.markdown
Created April 1, 2011 07:51
test of markdown

First Level

Second

  • you
@iveney
iveney / compilation_err.cpp
Created April 21, 2011 23:07 — forked from anonymous/gist:935681
Compilation error message
/usr/local/include/boost/graph/random.hpp: In function ‘void boost::detail::randomize_property(G&, RandomGenerator&, Property, boost::edge_property_tag) [with Property = boost::edge_bundle_t, G = boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS, boost::no_property, EdgeProperty, boost::no_property, boost::listS>, RandomGenerator = boost::random::linear_congruential<int, 48271, 0, 2147483647, 399268537>]’:
/usr/local/include/boost/graph/random.hpp:255: instantiated from ‘void boost::randomize_property(G&, RandomGenerator&) [with Property = boost::edge_bundle_t, G = Graph, RandomGenerator = boost::minstd_rand]’
random_graph.cpp:34: instantiated from here
/usr/local/include/boost/graph/random.hpp:247: error: no match for ‘operator=’ in ‘pm. boost::adj_list_edge_property_map<Directed, Value, Ref, Vertex, Property, Tag>::operator[] [with Directed = boost::undirected_tag, Value = EdgeProperty, Ref = EdgeProperty&, Vertex = long unsigned int, Property = boost::property<boost::edge_bundle_t, Edg
@iveney
iveney / gist:1045390
Created June 24, 2011 18:39
Javascript to draw a Sierpinski triangle in HTML5 canvas
var ctx;
var width;
var height;
var length;
var pline;
var MAX_LEVEL = 8;
var level;
function init() {
canvas = document.getElementById('tutorial');
@iveney
iveney / m4atag
Created July 12, 2011 15:56
m4a file tagger. Especially used as subroutine for to extract tags from file name.
#!/usr/bin/env python
# Author: Zigang Xiao <iveney # gmail.com>
# Date : 07/12/2011
"""A python utility (wrapper for mutagen.m4a) to udpate tags for m4a file type.
Relies on m4a module in mutagen.
"""
from mutagen.m4a import M4A
#!/usr/bin/env python
import string
import re
import sys
def get_gbk(value):
result = ''
for i in value:
result = result + chr(ord(i))
@iveney
iveney / utf2gbk.py
Created July 24, 2011 19:57
Rename files that have GBK encoded filenames but wrongly encoded in UTF8
#!/usr/bin/env python
import sys
import os
import unicodedata
for name in sys.argv[1:]:
try:
new_name = unicodedata.normalize("NFC", name.decode('utf8'))
new_name = new_name.encode('latin-1').decode('gbk')
iveney@iveney-mbp:~$ # find the IP of dapenti.com
iveney@iveney-mbp:~$ dig dapenti.com
; <<>> DiG 9.7.3-P3 <<>> dapenti.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30857
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
@iveney
iveney / curve fit.py
Created December 4, 2011 01:59
curve fit
"""
Fit a curve using polynomial order of n,
where n is the number of data points
"""
from scipy import *
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
#xs = array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
@iveney
iveney / ip_location.php
Created December 6, 2011 21:57
alfred extension for finding your ip location
<?php
$ip = $argv[1];
$tags = get_meta_tags("http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=$argv[1]");
print "{$tags['city']}, {$tags['region']}, {$tags['country']}";
?>