Skip to content

Instantly share code, notes, and snippets.

View lukecampbell's full-sized avatar

Luke Campbell lukecampbell

View GitHub Profile
@tmc
tmc / gist:777085
Created January 12, 2011 23:08
multiprocessing gevent chat example
import sys
import gevent
from gevent.monkey import patch_all; patch_all()
from gevent import server, event, socket
from multiprocessing import Process, current_process, cpu_count
"""
Simple multiprocess StreamServer that proxies messages between clients.
Avoids using a multiprocessing.Event since it blocks on a semaphore.
@lukecampbell
lukecampbell / couch
Last active December 14, 2015 17:09
utility scripts
#!/usr/bin/env ruby
couchdb = "http://localhost:5984/"
if ARGV[0] == 'admin'
couchdb = couchdb + '_utils/index.html'
exec 'open ' + couchdb
elsif ARGV[0] == 'wipe'
require 'couchrest'
cr = CouchRest.new('http://localhost:5984')
@theconektd
theconektd / github.css
Created April 30, 2012 02:11
Github Markdown CSS - for Markdown Editor Preview
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
@jboner
jboner / latency.txt
Last active July 5, 2024 02:48
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@lukecampbell
lukecampbell / wrapper.py
Created November 15, 2012 18:46
IPython gevent wrapper
import sys
import select
import gevent
def stdin_ready():
infds, outfds, erfds = select.select([sys.stdin], [], [], 0)
if infds:
return True
else:
return False
@lukecampbell
lukecampbell / load_datasets.py
Created November 15, 2012 21:30
dataset loader
# IPython log file
from pyon.ion.stream import StandaloneStreamPublisher
from ion.services.dm.utility.granule_utils import time_series_domain
from ion.services.dm.utility.granule import RecordDictionaryTool
import numpy as np
import time
#params = ['time','temp']
@lukecampbell
lukecampbell / load_datasets.py
Last active December 11, 2015 10:38
Load datasets and streamer utilities
# IPython log file
from ion.services.dm.utility.granule_utils import time_series_domain
from interface.services.dm.ipubsub_management_service import PubsubManagementServiceClient
from interface.services.dm.idataset_management_service import DatasetManagementServiceClient
from interface.services.dm.iingestion_management_service import IngestionManagementServiceClient
from interface.services.sa.idata_product_management_service import DataProductManagementServiceClient
from interface.services.dm.idata_retriever_service import DataRetrieverServiceClient
from ion.services.dm.inventory.dataset_management_service import DatasetManagementService
from interface.services.sa.idata_acquisition_management_service import DataAcquisitionManagementServiceClient
@lukecampbell
lukecampbell / timer.py
Last active December 11, 2015 20:38
Quick with context to get the time it takes to do something in Python
#!/usr/bin/env python
'''
@author Luke Campbell
'''
import gevent_profiler
import time
class TimeIt(object):
def __init__(self, message=''):
@blazetopher
blazetopher / 00_coi-services.py
Last active December 15, 2015 20:29
Read OOI Notebook Walkthrough.md below for instructions. NOTE: There are unresolved issues with gevent. Also, this has not been tested with any kind of service/deploy support in coi-services.
# Fix the ipython path
project_path = '/Users/cmueller/Development/OOI/Dev/code/coi-services'
virtualenv_path = '/Users/cmueller/Development/OOI/Dev/virtenvs/clean27'
import IPython
IPython.sys.path = ['',
'{0}/eggs/gevent-0.13.7-py2.7-macosx-10.6-intel.egg'.format(project_path),
'{0}/eggs/coverage-3.5.2-py2.7-macosx-10.6-intel.egg'.format(project_path),
'{0}'.format(project_path),
'{0}/eggs/objgraph-1.7.2-py2.7.egg'.format(project_path),
@lukecampbell
lukecampbell / python.supervisord.plist
Last active December 17, 2015 01:09
launchd plist file for starting supervisord on startup
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>python.supervisord</string>
<key>ProgramArguments</key>
<array>