Skip to content

Instantly share code, notes, and snippets.

View shelling's full-sized avatar

shelling shelling

View GitHub Profile
@shelling
shelling / em_helper.py
Created November 11, 2009 12:13
EM theory assignment 3
from math import *
from numpy import *
class Layer:
def __init__(self, params = {}):
self.eps = params["eps"]
self.l_coef = params["l_coef"]
self.n = sqrt( self.eps )
@shelling
shelling / .gitignore
Created December 21, 2009 16:39
famous maze problem
a.out
@shelling
shelling / matplotlib pin.py
Created December 30, 2009 16:11
matplotlib pin
x = numpy.arange(0,math.pi,0.01)
pylab.plot(x, numpy.sin(x))
pylab.xlim((0, x[-1]))
pylab.grid(True)
pylab.savefig("simple.png")
pylab.gcf().clear()
os.system("open simple.png")
@shelling
shelling / class_method.py
Created January 15, 2010 10:13
show how to write a class method in Python
class Hello():
def world(self):
return "world"
world = classmethod(world)
def foo():
return "foo"
@shelling
shelling / subndarray.py
Created January 27, 2010 10:24
using numpy.ndarray to construct Plane class
#!/usr/bin/env python
#-*- mode: python -*-
import numpy
class Plane(numpy.ndarray):
"""
"""
def __new__(cls, abuffer):
@shelling
shelling / rack-simple.rb
Created February 16, 2010 08:46
Simplest Rack Application Example
#!/usr/bin/env ruby
require "rubygems"
require "rack"
require "rack/showexceptions"
require "rack/request"
require "rack/response"
class Hash
@shelling
shelling / whois_twnic.pl
Created March 31, 2010 11:25
Example of how to do POST action with HTTP::Request::Common
#!/usr/bin/env perl
use HTTP::Request::Common;
use LWP::UserAgent;
use pQuery;
sub whois_tanic {
my ($query, $sld) = @_;
@shelling
shelling / content_for.pl
Created May 7, 2010 18:05
content_for() in Perl
sub content_for {
my ($tag, $params, $content) = @_;
my $res = "<$tag";
for (keys %{$params}) {
$res .= " $_=$params->{$_}";
}
$res .= ">\n";
if (ref($content) ~~ /CODE/) {
$res .= $content->();
@shelling
shelling / hello_parallel_mpi_simple.pl
Created June 15, 2010 09:47
Hello, Parallel::MPI
#!/usr/bin/env perl
use 5.010;
use Parallel::MPI::Simple;
$total = 0;
MPI_Init();
myrank = MPI::Comm::WORLD.rank()
csize = MPI::Comm::WORLD.size()
if myrank % 2 == 0 then
if myrank + 1 != csize then
hello = "Hello, I'm #{myrank}, you must be #{myrank+1}"
MPI::Comm::WORLD.send(hello, myrank + 1, 0)
end
else
msg, status = MPI::Comm::WORLD.recv(myrank - 1, 0)