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 / linear_system.matlab
Last active August 29, 2015 14:01
Solutions to under-constrained linear system
>> rng(0)
>> A=randi(10, 2, 5); b=randi(100, 2, 1);
% A = b =
% 9 7 8 7 8 28
% 10 8 4 2 1 5
>> x1=A\b; x2=pinv(A)*b
% x1 = x2 =
% Compare Ordinary Least square (no regularization), L2-reguarlized (Ridge),
% L1-regualarized (Lasso) regression in finding the sparse coefficient
% in a underdetermined linear system
rng(0); % for reproducibility
m = 50; % num samples
n = 200; % num variables, note that n > m
A = rand(m, n);
x = zeros(n, 1);
@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 / 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-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 / 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']}";
?>
% sparse signal recovery using L1
rng(0);
N = 256; R = 3; C = 2;
% some superposition of sinoisoids, feel free to change and experiment
f = @(x) .5*sin(3*x).*cos(.1*x)+sin(1.3*x).*sin(x)-.7*sin(.5*x).*cos(2.3*x).*cos(x);
x = linspace(-10*pi, 10*pi, N);
y = f(x);