Skip to content

Instantly share code, notes, and snippets.

@seungjin
seungjin / gist:961491
Created May 8, 2011 16:48
scratch.. getting scroll position/location
<html>
<script>
var scrollCheck = function() {
var vscroll = (document.all ? document.scrollTop : window.pageYOffset);
console.log(vscroll);
@seungjin
seungjin / gist:959694
Created May 6, 2011 20:12
html escape using ruby and python
giliani:~$ irb
>> require 'cgi'
=> true
>> p CGI.escapeHTML('hello <world> & test " hi " 123 ')
"hello &lt;world&gt; &amp; test &quot; hi &quot; 123 "
=> nil
>>
@seungjin
seungjin / python_lambda_test_1.py
Created May 1, 2011 05:04
speed test with different expressions
#!/opt/local/bin/python
from datetime import datetime
r1 = []
for a in range(1,10001) :
begin = datetime.now()
reduce(lambda x,y: x+" " +y,map(lambda x: x.upper(), ["diversity","is","good"]))
end = datetime.now()
r1.append(end-begin)
@seungjin
seungjin / run_cmd_func.py
Created April 29, 2011 23:59
run shell command in python
import subprocess
run_cmd = lambda c : subprocess.Popen(c.split(), stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=False).stdout.read()
run_cmd = lambda c,a : subprocess.Popen(c.split(None,a), stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=False).stdout.read()
@seungjin
seungjin / gist:911668
Created April 9, 2011 18:52
ruby time server and client
# Date Time Server - server side using thread
# usage: ruby p068dtserver.rb
require "socket"
dts = TCPServer.new('localhost', 20000)
loop do
Thread.start(dts.accept) do |s|
print(s, " is accepted\n")
s.write(Time.now)
#!/usr/bin/env ruby
# $ netcat $HOST $PORT -w 1 -q 0 </dev/null && do_something
require 'socket'
require 'timeout'
def is_port_open?(ip,port)
import sys
import os
import asyncore
import pyinotify
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CREATE(self, event):
#print "Creating:", event.pathname
#I will use boto to connect amazon / euca2ool or irod??
os.system('scp "%s" "%s:%s"' % (event.pathname, 'seungjin@localhost', '/home/seungjin/mydropbox') )
#!/usr/bin/python
import httplib
import urllib
from urlparse import urlparse
import string
import datetime
import getpass
import json
@seungjin
seungjin / PostMethodExample.java
Created March 2, 2011 03:54
Post Method Example
import java.net.*;
import java.io.*;
public class PostMethodExample {
public static void main(String args[]) {
try {
// Construct data
@seungjin
seungjin / webserver.py
Created March 2, 2011 03:53
post debugger
import string,cgi,time
from os import curdir, sep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
#import pri
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
print "do_GET"
self.send_response(200)
self.send_header('Content-type', 'text/html')