Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@karlseguin
karlseguin / dnscache.go
Created June 12, 2013 07:43
Cache DNS responses and refresh them using a single goroutine on a 1 minute timer. Avoids having a spike of threads from cgo launched under load.
package dnscache
import (
"net"
"sync"
"time"
"math/rand"
)
var (
@creationix
creationix / run.js
Last active March 7, 2017 18:36
universal callback/continuable/thunk generator runner
function run(generator) {
// Pass in resume for no-wrap function calls
var iterator = generator(resume);
var data = null, yielded = false;
next();
check();
function next(item) {
var cont = iterator.next(item).value;

Changing the Public API

When I started looking for ways to help on the "github.com/alecthomas/gozmq" package a few months ago, a recurring topic in discussions was that an earlier decision to provide a hidden struct type through a public interface type had become restrictive. We couldn't just drop the interface and make the struct public because that would be backwards-incompatible. Or could we?

No

This had to be the first considered option, and was the standing decision at the time. If we could continue providing what the package aims to provide without breaking backwards compatibility, then by all means, we should not break it.

Unfortunately this meant we couldn't provide all that we aimed to provide. Or could we?

@max-mapper
max-mapper / helloworld.js
Created November 27, 2012 06:55
droneduino
var serialport = require('node-serialport')
var sp = new serialport.SerialPort("/dev/ttyO3", {
parser: serialport.parsers.raw,
baud: 9600
})
sp.on('data', function(chunk) {
console.log(chunk.toString('hex'), chunk.toString(), chunk)
})
@mattb
mattb / gist:3888345
Created October 14, 2012 11:53
Some pointers for Natural Language Processing / Machine Learning

Here are the areas I've been researching, some things I've read and some open source packages...

Nearly all text processing starts by transforming text into vectors: http://en.wikipedia.org/wiki/Vector_space_model

Often it uses transforms such as TFIDF to normalise the data and control for outliers (words that are too frequent or too rare confuse the algorithms): http://en.wikipedia.org/wiki/Tf%E2%80%93idf

Collocations is a technique to detect when two or more words occur more commonly together than separately (e.g. "wishy-washy" in English) - I use this to group words into n-gram tokens because many NLP techniques consider each word as if it's independent of all the others in a document, ignoring order: http://matpalm.com/blog/2011/10/22/collocations_1/

@roryokane
roryokane / .rbenv-version
Created September 4, 2012 12:31
editing Wikipedia ISBN calculation code
1.9.3-p194
@jstorimer
jstorimer / port_scanner.rb
Created August 30, 2012 03:40
Simple, parallel port scanner in Ruby built with connect_nonblock and IO.select.
require 'socket'
# Set up the parameters.
PORT_RANGE = 1..512
HOST = 'archive.org'
TIME_TO_WAIT = 5 # seconds
# Create a socket for each port and initiate the nonblocking
# connect.
sockets = PORT_RANGE.map do |port|
@bsingr
bsingr / actor.rb
Created August 26, 2012 16:55
Different methods to spawn Celluloid Actors.
# instantiate a cat object named 'Garfield' within its own actor thread
cat = Cat.new 'Garfield'
# blocking (the main thread waits until the cat has finished..)
cat.spray
# non-blocking
cat.spray!
# cats do what cats do
16:19 t432: What is the best way to approach the following problem.... A user logs in, application connects to database, retrieves latest 100 records and display the content. if user scrolls to bottom of page, retrieve next 100 records and display continue till end. In addition if a new record is created whilst logged in automatically display record on top... Might look familiar you use twitter
16:19 mattgordon has joined (~mattgordo@208.66.31.98)
16:20 will_: Great :)
16:20 Psi-Jack: I'm also using the primary_conninfo line in recovery.conf.
16:20 Psi-Jack: And trigger_File.
16:20 Psi-Jack: But, it's simply not streaming. :)
16:20 Psi-Jack: I'
16:20 luckyruby: t432, what web framework are u using?
16:21 orf_ has left IRC (Quit: Leaving)
16:21 bwlang_ has joined (~anonymous@70-91-134-14-ma-ne.hfc.comcastbusiness.net)
@pauldix
pauldix / gist:2830675
Created May 29, 2012 21:00
ideas for fetching
# set the thread pool size and the timeout in seconds.
fetcher = Feedzirra::Fetcher.new({:thread_pool_size => 100, :timeout => 5})
# some feed data objects. also include feed_entry data objects
feeds = [Feed.new({:entries => [], etag => "..", :last_modified => "...", :url => "...", :feed_url => "...", :title => ""})]
# async style
fetcher.get(feeds, :on_success => lambda {|feed, updated_feed| ...}, :on_failure => lambda {|feed, failure_object| ...})
# that returns before finishing fetching the feeds. just adds them to a thread-safe queue to be processed by a worker pool.
# the failure condition could actually call fetcher.get on the failed feed again if you wanted to retry.