Skip to content

Instantly share code, notes, and snippets.

View jlongtine's full-sized avatar

Joel Longtine jlongtine

View GitHub Profile
@stevebartholomew
stevebartholomew / gist:50180
Created January 21, 2009 20:52
Simple database backup rake task for Rails using mysqldump
namespace :backup do
desc "Backup database"
task :db do
RAILS_ENV = "development" if !defined?(RAILS_ENV)
app_root = File.join(File.dirname(__FILE__), "..", "..")
settings = YAML.load(File.read(File.join(app_root, "config", "database.yml")))[RAILS_ENV]
output_file = File.join(app_root, "..", "backup", "#{settings['database']}-#{Time.now.strftime('%Y%M%d')}.sql")
system("/usr/bin/env mysqldump -u #{settings['username']} -p#{settings['password']} #{settings['database']} > #{output_file}")
@gruber
gruber / Liberal Regex Pattern for All URLs
Last active May 29, 2024 00:03
Liberal, Accurate Regex Pattern for Matching All URLs
The regex patterns in this gist are intended to match any URLs,
including "mailto:foo@example.com", "x-whatever://foo", etc. For a
pattern that attempts only to match web URLs (http, https), see:
https://gist.github.com/gruber/8891611
# Single-line version of pattern:
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
@leesmith
leesmith / URLs from routes
Created March 13, 2011 19:58
Rails one-liner to get URLs from rake routes
# http://trevmex.com/post/3822870892/rails-one-liner-to-get-urls-from-rake-routes
rake routes | sed -e "1d" -e "s,^[^/]*,,g" | awk '{print $1}' | sort | uniq
@jboner
jboner / latency.txt
Last active July 19, 2024 03:35
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
@jdp
jdp / loglog.go
Last active December 20, 2015 07:48
LogLog and HyperLogLog estimators in Golang
package main
import (
// "encoding/binary"
"crypto/rand"
"fmt"
"hash"
"hash/fnv"
"io"
"io/ioutil"
@kavu
kavu / example.go
Created September 28, 2013 10:01
Minimal Golang + Cocoa application using CGO. Build with `CC=clang go build`
package main
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>
int
StartApp(void) {
[NSAutoreleasePool new];
@ericboehs
ericboehs / README.md
Last active March 10, 2022 12:43
Easy way to display progress in command line ruby script

Usage

Simply replace things and thing with whatever large object you're iterating over and put your iteration code in place of the code comment.

Explanation

In ruby you can append with_index and an index variable to your enumerators and it will give you an iterator counter (i). Using this we calculate a progress precentage:

(i.to_f / things.length * 100).to_i
@devdazed
devdazed / slack-pagerduty-oncall.py
Last active April 18, 2024 10:28
Updates a Slack User Group with People that are on call in PagerDuty
#!/usr/bin/env python
from __future__ import print_function
import json
import logging
from urllib2 import Request, urlopen, URLError, HTTPError
from base64 import b64decode

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@sjparkinson
sjparkinson / RDS-Aurora-CloudFormation-Example.yaml
Last active May 10, 2022 10:43
A basic CloudFormation template for an RDS Aurora cluster.
---
AWSTemplateFormatVersion: 2010-09-09
Description: >
A basic CloudFormation template for an RDS Aurora cluster.
Parameters:
DatabaseUsername:
AllowedPattern: "[a-zA-Z0-9]+"
ConstraintDescription: must be between 1 to 16 alphanumeric characters.