Skip to content

Instantly share code, notes, and snippets.

View bcoe's full-sized avatar
💭
hackin'

Benjamin E. Coe bcoe

💭
hackin'
View GitHub Profile
@raisch
raisch / regex_tokenizer.js
Created June 10, 2011 13:29
Regular Expression Sentence Tokenizer (English)
// tokenize(str)
// extracts semantically useful tokens from a string containing English-language sentences
// @param {String} the string to tokenize
// @returns {Array} contains extracted tokens
function tokenize(str) {
var punct='\\['+ '\\!'+ '\\"'+ '\\#'+ '\\$'+ // since javascript does not
'\\%'+ '\\&'+ '\\\''+ '\\('+ '\\)'+ // support POSIX character
'\\*'+ '\\+'+ '\\,'+ '\\\\'+ '\\-'+ // classes, we'll need our
@chetan
chetan / yardoc_cheatsheet.md
Last active April 16, 2024 23:49
YARD cheatsheet
@jotto
jotto / google_oauth2_access_token.rb
Created June 14, 2012 21:15
ruby command line script for generating google oauth2 access token
# (create oauth2 tokens from Google Console)
client_id = ""
client_secret = ""
# (paste the scope of the service you want here)
# e.g.: https://www.googleapis.com/auth/gan
scope = ""
@eprothro
eprothro / shards.yml
Created April 12, 2013 19:28
Dynamic Octopus configuration for master/slave horizontal DB scaling with a Rails application on the Heroku stack. See the wiki page for more info: https://github.com/tchandy/octopus/wiki/Replication-with-Rails-on-Heroku. Props to Heroku for the idea, gleaned from the dynamic database.yml they inject at build-time for rails apps.
<%
require 'cgi'
require 'uri'
def attribute(name, value, force_string = false)
if value
value_string =
if force_string
'"' + value + '"'
else
@romaonthego
romaonthego / htmltest.m
Created September 23, 2013 16:08
UITextView with HTML text (iOS 7)
- (void)viewDidLoad
{
[super viewDidLoad];
UITextView *textView = [[UITextView alloc] init];
textView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:textView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg' width=70 height=100 />";
@pmarreck
pmarreck / rb_snowflake_id.rb
Created December 20, 2013 03:20
An implementation of Twitter's Snowflake ID generation algorithm in pure Ruby. Note: I didn't rewrite the bits that run this as a service. This is just the algorithm.
require 'monitor'
class IdWorker
attr_reader :worker_id, :datacenter_id, :reporter, :logger, :sequence, :last_timestamp
TWEPOCH = 1288834974657
WORKER_ID_BITS = 5
DATACENTER_ID_BITS = 5
MAX_WORKER_ID = (1 << WORKER_ID_BITS) - 1
@0xabad1dea
0xabad1dea / rsa-not-buying-it.md
Last active May 4, 2022 21:59
Sorry, RSA, I'm just not buying it

Sorry, RSA, I'm just not buying it

I want to be extremely clear about three things. First, this is my personal opinion – insert full standard disclaimer. Second, this is not a condemnation of everyone at RSA, present and past. I assume most of them are pretty okay, and that the problem is confined to a few specific points in the company. However, “unknown problem people making major decisions at RSA” is a bit unwieldy, so I will just say RSA. Third, I'm not calling for a total boycott on RSA. I work almost literally across the street from them and I don’t want to get beat up by roving gangs of cryptographers at the local Chipotle.

RSA's denial published last night is utter codswallop that denies pretty much everything in the world except the actual allegations put forth by Reuters and hinted at for months by [other sources](http://li

@forkfork
forkfork / atomic_redis.md
Last active May 3, 2019 01:02
Atomic Json modifications with Redis

Atomic Operations in Redis

Redis is a commonly used as a mini 'database' for caching, shared queues, and similar. It is generally fast & reliable for these tasks. Redis does not support nested data types, and misusing redis for this type of thing can end up with the situation described below.

Imagine that we want to store the following data in Redis:

set users '[{"user":"tim", "pages": ["aaa", "bbb"]}]'

@jberkus
jberkus / gist:6b1bcaf7724dfc2a54f3
Last active January 7, 2024 21:26
Finding Unused Indexes
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@ceejbot
ceejbot / monitoring.md
Last active November 15, 2022 08:53
monitoring manifesto

monitoring: what I want

I've recently shifted from a straight engineering job to a job with a "dev/ops" title. What I have discovered in operations land depresses me. The shoemaker's children are going unshod. Operations software is terrible.

What's driving me craziest right now is my monitoring system.

what I have right now

What I have right now is Nagios.