Skip to content

Instantly share code, notes, and snippets.

Scruggs not drugs

Norman Clarke norman

Scruggs not drugs
View GitHub Profile
norman / fixtures_spec.rb
Created Oct 13, 2021
Test the validity of your Rails fixtures
View fixtures_spec.rb
# frozen_string_literal: true
require "rails_helper"
describe "Fixtures" do
fixture_table_names.each do |table_name|
model_class = table_name.singularize.classify.constantize
it "has valid #{table_name}" do
expect(model_class.all).to all be_valid
norman / earthdistance.rb
Last active Oct 5, 2021
Geographic Searches With Postgres's Earthdistance and Cube Extensions
View earthdistance.rb
#!/usr/bin/env ruby
= Geographic Searches With Postgres's Earthdistance and Cube Extensions
This program shows how to easily create a Postgres database that uses the Cube
and Earthdistance extensions to perform fast queries on geographic data.
Briefly, the problem this code solves is "show me all places within 50
kilometers of New York City."
norman / character_reference.rb
Last active Sep 9, 2021
HTML entities? We don't need no stinkin' HTML entities.
View character_reference.rb
# coding: utf-8
# Encode any codepoint outside the ASCII printable range to an HTML character
# reference (
def encode(string)
string.each_codepoint.inject("") do |buffer, cp|
cp = "&#x#{cp.to_s(16)};" unless cp >= 0x20 && cp <= 0x7E
buffer << cp
norman / gist:1192140
Created Sep 4, 2011
string interpolation vs array join
View gist:1192140
require "benchmark"
puts %x{ruby -v} + "\n"
Benchmark.bmbm do |x|
N = 1_000_000
a = "aa"
b = "bb"
View temp.txt
h1#logo {style: "use a stylesheet please"}
< This is inline content
and can be on multiple lines though I'm
not sure why you'd want to do that
> This is block content
norman / Gemfile
Last active Nov 21, 2019
Delayed Job without Rails
View Gemfile
source ''
gem 'delayed_job'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'pg'
norman /
Created May 30, 2012
Git trick to show additions and deletions between branches
git log stable..rails3 --pretty=tformat: --numstat | awk '{ add += $1 ; subs += $2 ; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s\n",add,subs,loc }' -
added lines: 13821 removed lines: 16327 total lines: -2506

Keybase proof

I hereby claim:

  • I am norman on github.
  • I am compay ( on keybase.
  • I have a public key whose fingerprint is 1A08 8ED4 32C3 612F 5FF5 677E 74BA BFD3 3159 0D75

To claim this, I am signing this object:

View test_streaming.lua
require "wsapi.cgi"
require "socket"
local function sleep(n), nil, n)
local function run(wsapi_env)
norman / object.lua
Created Apr 11, 2011
ridiculously simple object oriented Lua
View object.lua
local class = {}
local methods = {}
local instance = {}
return setmetatable(instance, {__index = methods})
return class