Skip to content

Instantly share code, notes, and snippets.

#!/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)
@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)
@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 / 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 / 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 / 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 / atmo_boot.rb
Created May 21, 2011 02:31
atmo_boot script
##
## All files that are a part of this project, unless explicitly noted otherwise,
## are covered by the following license:
##
## Copyright (c) 2011, The Arizona Board of Regents on behalf of The University
## of Arizona
##
## All rights reserved.
##
## Developed by: iPlant Collaborative as a collaboration between participants at
@seungjin
seungjin / license.txt
Created May 21, 2011 21:53
my work license
##
## All files that are a part of this project, unless explicitly noted otherwise,
## are covered by the following license:
##
## Copyright (c) 2011, The Arizona Board of Regents on behalf of The University
## of Arizona
##
## All rights reserved.
##
## Developed by: iPlant Collaborative as a collaboration between participants at
##
## All files that are a part of this project, unless explicitly noted otherwise,
## are covered by the following license:
##
## Copyright (c) 2011, The Arizona Board of Regents on behalf of The University
## of Arizona
##
## All rights reserved.
##
## Developed by: iPlant Collaborative as a collaboration between participants at
@seungjin
seungjin / gist:991895
Created May 25, 2011 20:37
for/while statements are for college students
def loop (fnc,n,o=0):
o = o + 1
fnc()
loop(fnc,n,o) if n > o else None
def hi():
print "h"
loop(hi,10)