Skip to content

Instantly share code, notes, and snippets.

@presci
presci / TestWriter.java
Created May 11, 2012 18:31
Buffered Writer in java
package com.etrade.neo.util;
import java.io.StringWriter;
public class TestWriter {
public static void main(String[] args) {
String source = "Now is the time for all good men\\n"
+ " to come to the aid of their country\\n"
+ " and pay their due taxes.";
@presci
presci / graburl.py
Created May 11, 2012 18:33
Semaphore example
import threading, os, re, sqlite3, sys
from subprocess import *
class GrabUrl(threading.Thread):
def __init__(self, arg0):
threading.Thread.__init__(self)
self.host=arg0
def run(self):
print "Getting " + self.host
arr=['wget', self.host]
@presci
presci / GrabUrl2.py
Created May 11, 2012 18:34
Semaphore example in python 2
import threading
import urllib2
import time, random
class GrabUrl(threading.Thread):
def __init__(self, arg0):
threading.Thread.__init__(self)
self.host=arg0
def run(self):
k=random.randint(10,20)
@presci
presci / sample_erlang_js
Created July 5, 2012 23:26
erlang_js examples
1> {ok, JS}=js_driver:new().
{ok,#Port<0.1611>}
2> js:define(JS, <<"var hello=function(){return 'hello world';}">>).
ok
3> js:call(JS, <<"hello">>, []).
{ok,<<"hello world">>}
4> js:define(JS, <<"var kelly=function(){ return {\"hello\":\"world\"};}">>).
ok
5> js:call(JS, <<"kelly">>, []).
{ok,{struct,[{<<"hello">>,<<"world">>}]}}
@presci
presci / cowboy_dispather
Created July 12, 2012 18:04
cowboy dispatcher config
Dispatch=[
{'_', [
{[<<"static">>, '...'], cowboy_http_static,
[{directory, "./priv"},
{mimetypes, [
{<<".css">>, [<<"text/css">>]},
{<<".js">>, [<<"application/javascript">>]},
{<<".html">>, [<<"text/html">>]}
]}
]},
@presci
presci / neo_handler_multipart.erl
Created December 28, 2012 17:47
extend/cowboy file upload
-module(neo_handler_multipart).
-behaviour(cowboy_http_handler).
-export([init/3, handle/2, terminate/2]).
init({_Transport, http}, Req, []) ->
{ok, Req, {}}.
handle(Req, State) ->
{Result, Req2} = acc_multipart(Req),
@presci
presci / ranch error
Last active December 22, 2015 13:58
ranch error
This is my erlang code
-module(bohemian).
-export([start/0]).
start()->
ok = application:start(crypto),
ok = application:start(ranch),
ok = application:start(cowboy),
ok = application:start(bohemian).
@presci
presci / keyvaluepair
Created October 21, 2013 00:49
python iterate over the map and create key value pairs
K={'hello10':'world10', 'hello9':'world9', 'hello1':'world1'}
K.keys().sort()
Str = ''
for i in K.keys():
Str += i + '=' + K[i] + '&'
print Str[:-1]
@presci
presci / bindargs.html
Created December 31, 2013 22:44
bind.args
<html>
<head></head>
<body>
<div id="leaf"></div>
<div id="low"></div>
<input type="button" id="query" value="query"></button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
var discovery=function(){
};
@presci
presci / division.erl
Last active August 29, 2015 13:57
division in erlang
-module(divi).
-export([start/2]).
start(A, B)->
ds(A, B, 0).