Skip to content

Instantly share code, notes, and snippets.

@seungjin
seungjin / submit.rb
Created May 2, 2009 06:15
simple ftp upload program
#!/usr/bin/env ruby
require 'net/ftp'
ftp = Net::FTP.new('www.myftpserver.com')
ftp.passive = true
ftp.login('myuserid','mypassowrd')
files = ftp.chdir('/data')
#Currnet localpath
#!/usr/bin/env python
# PowerSet program
def PowerSet(base):
power_set = []
b = len(base)
map(lambda g: power_set.append(map(lambda x: base[x],
filter(lambda x: g[x], range(0, b)))),
map(lambda value: map(lambda x: (value >> x) & 1, range(b - 1, -1, -1)),
map(lambda value: value ^ (value / 2), range(0, 2**b))))
@seungjin
seungjin / php recursion loop
Created May 7, 2009 15:01
php recursion loop
<?php
// php loop based on recursion
// why do we need while / for statement in program language?
// and in php, I cannot pass php function to php function as function arg. :-(
// Anonymous functions are available since PHP 5.3.0. http://us2.php.net/manual/en/functions.anonymous.php
// I am using 5.2.6 now.
class Foo
{
public function loop($a,$b)
{
@seungjin
seungjin / recursion loop in ecmascript
Created May 7, 2009 16:10
recursion loop in ecmascript
// get rid of for/while in your ecmascrip!
loop = function(givenF,a,b) {
if ( a >= 0 && b >= a ) { eval(givenF()); a++; loop(givenF,a,b); }
}
sayHello = function() {
print("say hello\n");
}
loop(sayHello,1,4);
@seungjin
seungjin / recursion loop in python
Created May 7, 2009 22:36
// get rid of for/while in your python
#!/usr/bin/env python
# get rid of for/while in your python code!
def loop(givenF,a,b):
if ( a >= 0 and b >= a) :
givenF()
a += 1
loop(givenF,a,b)
def sayHello():
print("say hello")
@seungjin
seungjin / dump.js
Created May 8, 2009 22:40
function dump() - Javascript equivalent of PHP's print_r() function
/**
* this source is from http://www.openjs.com/scripts/others/dump_function_php_print_r.php
*/
/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
* The level - OPTIONAL
* Returns : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
<?php
function get_microtime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
$start_time = get_microtime();
// I do not use this function. Don't need it. Record this code just for reference
#!/usr/bin/env python
# copy files into target directory with timestamp
import os
import sys
from datetime import date
print("USAGE: python cpHere.py /Users/seungjin/Desktop/a");
#!/usr/bin/env python
# connectionCheck
import sys
from urllib2 import urlopen
import socket
host = sys.argv[1]
port = int(sys.argv[2])
size = 1024
@seungjin
seungjin / imageRotate.js
Created June 17, 2009 01:33
image ratate javascript (rotate image 90 degree....)
/* image rotate javascript */
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Benoit Asselin | http://www.ab-d.fr */
function rotate(p_deg) {
if(document.getElementById('canvas')) {
/*
Ok!: Firefox 2, Safari 3, Opera 9.5b2