Skip to content

Instantly share code, notes, and snippets.

View jaychoo's full-sized avatar
☢️

Jay Choo jaychoo

☢️
  • New York, NY
View GitHub Profile
@jaychoo
jaychoo / websocketUDPBridge.py
Created September 9, 2016 19:14 — forked from adzialocha/websocketUDPBridge.py
Websocket-UDP Bridge with HTTP Server
import time, sys, os, pkg_resources
import SocketServer
from twisted.python import log
from twisted.internet import reactor
from twisted.application import service
from twisted.internet.protocol import DatagramProtocol, Protocol, Factory
from twisted.web.server import Site
@jaychoo
jaychoo / udpserver.py
Created September 7, 2016 22:13 — forked from jamiesun/udpserver.py
tornado UDP server
#!/usr/bin/env python
#coding=utf-8
import socket
import os
import errno
from tornado.ioloop import IOLoop
from tornado.platform.auto import set_close_exec
class UDPServer(object):
def __init__(self, io_loop=None):
@jaychoo
jaychoo / gist:5bf8b848c21ffa65a6c9ee6a2453e49d
Created July 21, 2016 04:47 — forked from methane/gist:2185380
Tornado Example: Delegating an blocking task to a worker thread pool from an asynchronous request handler
from time import sleep
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, asynchronous, RequestHandler
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
def run_background(func, callback, args=(), kwds={}):
def _callback(result):
@jaychoo
jaychoo / nginx-uwsgi-python3
Created January 19, 2016 22:56 — forked from simoncoulton/nginx-uwsgi-python3
Setting up Nginx, uWSGI & Python3
======================================
Setting up Nginx, uWSGI and Python3
======================================
First off, I'm traditionally a PHP developer, but am looking at moving across to Python. I really struggled to find decent documentation on how to get a server up and running for deploying Python web applications from the point of view of someone coming from PHP. The main problems I came across with documentation were:
1) Only showed you how to run the server for a single web application.
2) Only showed you how to configure the app, not the server it was running on.
My preferred workflow for development is by setting up a new VM in VMware Fusion and then forwarding through all requests to that VM via /etc/hosts. This might not be the optimal way to get things up and running, but it works for me.
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@jaychoo
jaychoo / event_export.py
Created December 16, 2015 22:54 — forked from drmarshall/event_export.py
Example Mixpanel raw event export script
#! /usr/bin/env python
#
# Mixpanel, Inc. -- http://mixpanel.com/
#
# Python API client library to consume mixpanel.com analytics data.
import hashlib
import urllib
import time
try:
@jaychoo
jaychoo / redshift_example_using_psycopg2.py
Created October 21, 2015 13:25
Example on how to connect to redshift using psycopg2
__author__ = 'fbaldo'
import psycopg2
import pprint
configuration = { 'dbname': 'database_name',
'user':'user_name',
'pwd':'user_password',
'host':'redshift_endpoint',
#lang racket
(require net/http-client)
(require net/url)
(require json)
(require net/uri-codec)
(require racket/cmdline)
(define lg (make-logger 'currency-logger))
(current-logger lg)
import UIKit
import Foundation
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely()
class RemoteAPI {
func getData(completionHandler: ((NSArray!, NSError!) -> Void)!) -> Void {
let url: NSURL = NSURL(string: "http://itunes.apple.com/search?term=Turistforeningen&media=software")
let ses = NSURLSession.sharedSession()
@jaychoo
jaychoo / home-yet.py
Last active August 29, 2015 14:15 — forked from joewalnes/home-yet.py
#!/usr/bin/env python
"""A tiny script that polls your location on Google Latitude, and updates
the color of a Blink1 LED. http://shop.thingm.com/blink1/
Red = At work
Blue = At home
Green = On my way
Should work on Windows, OS-X and Linux. Requires Python 2.7 or later.