Skip to content

Instantly share code, notes, and snippets.

ers35 / json2sqlite.lua
Last active Jul 13, 2016
Convert to an SQLite database
View json2sqlite.lua
-- The author disclaims copyright to this source code.
-- Convert to an SQLite database
-- Convert the whole dataset at once like so:
-- find reddit_data -type f -exec time lua json2sqlite.lua {} \;
local cjson = require"cjson"
local sqlite = require"lsqlite3"
local db ="reddit_data.db")
#!/usr/bin/env bash
# Colours picked from
# Label definitions
declare -A LABELS
# Platform
phoet / menu.rb
Created Oct 15, 2013
curses example drawing a menu
View menu.rb
require "curses"
include Curses
def draw_menu(menu, active_index=nil)
4.times do |i|
menu.setpos(i + 1, 1)
jbenet /
Last active Jul 27, 2020
a simple git branching model

a simple git branching model (written in 2013)

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

klange /
Last active Feb 24, 2020
It's a résumé, as a readable and compilable C source file. Since Hacker News got here, this has been updated to be most of my actual résumé. This isn't a serious document, just a concept to annoy people who talk about recruiting and the formats they accept résumés in. It's also relatively representative of my coding style.

Since this is on Hacker News and reddit...

  • No, I don't distribute my résumé like this. A friend of mine made a joke about me being the kind of person who would do this, so I did (the link on that page was added later). My actual résumé is a good bit crazier.
  • I apologize for the use of _t in my types. I spend a lot of time at a level where I can do that; "reserved for system libraries? I am the system libraries".
  • Since people kept complaining, I've fixed the assignments of string literals to non-const char *s.
  • My use of type * name, however, is entirely intentional.
  • If you're using an older compiler, you might have trouble with the anonymous unions and the designated initializers - I think gcc 4.4 requires some extra braces to get them working together. Anything reasonably recent should work fine. Clang and gcc (newer than 4.4, at le
rgreenjr / postgres_queries_and_commands.sql
Last active Aug 10, 2020
Useful PostgreSQL Queries and Commands
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
warmwaffles / widget.rb
Created Jun 23, 2012
Have you wanted to ever fuzzy search on your model without actually running Solr or Sphinx? Well this little function can help ease you in
View widget.rb
class Widget < ActiveRecord::Base
# ..... extra crap here .....
scope :active, where(:status => [:active])
# This will fuzzy search the model for the provided query. It will split your
jboner / latency.txt
Last active Aug 11, 2020
Latency Numbers Every Programmer Should Know
View latency.txt
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
davatron5000 / gist:2254924
Created Mar 30, 2012
Static Site Generators
View gist:2254924

Backstory: I decided to crowdsource static site generator recommendations, so the following are actual real world suggested-to-me results. I then took those and sorted them by language/server and, just for a decent relative metric, their Github Watcher count. If you want a heap of other projects (including other languages like Haskell and Python) Nanoc has the mother of all site generator lists. If you recommend another one, by all means add a comment.


troy / send_remote_syslog.php
Last active Jun 20, 2020
Send UDP remote syslog message from PHP (RFC 3164)
View send_remote_syslog.php
# see for additional PHP syslog options
function send_remote_syslog($message, $component = "web", $program = "next_big_thing") {
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
foreach(explode("\n", $message) as $line) {
$syslog_message = "<22>" . date('M d H:i:s ') . $program . ' ' . $component . ': ' . $line;
socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, PAPERTRAIL_HOSTNAME, PAPERTRAIL_PORT);
You can’t perform that action at this time.