Skip to content

Instantly share code, notes, and snippets.

Avatar
🪕
Scruggs not drugs

Norman Clarke norman

🪕
Scruggs not drugs
View GitHub Profile
@norman
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
end
@norman
norman / earthdistance.rb
Last active Oct 5, 2021
Geographic Searches With Postgres's Earthdistance and Cube Extensions
View earthdistance.rb
#!/usr/bin/env ruby
=begin
= 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
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 (https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_reference_overview).
def encode(string)
string.each_codepoint.inject("") do |buffer, cp|
cp = "&#x#{cp.to_s(16)};" unless cp >= 0x20 && cp <= 0x7E
buffer << cp
end
end
@norman
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
!!!
html
head
body
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
p
> This is block content
@norman
norman / Gemfile
Last active Nov 21, 2019
Delayed Job without Rails
View Gemfile
source 'https://rubygems.org'
gem 'delayed_job'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'pg'
@norman
norman / git-log-deletions.sh
Created May 30, 2012
Git trick to show additions and deletions between branches
View git-log-deletions.sh
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
View keybase.md

Keybase proof

I hereby claim:

  • I am norman on github.
  • I am compay (https://keybase.io/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
#!/usr/local/bin/lua
require "wsapi.cgi"
require "socket"
local function sleep(n)
socket.select(nil, nil, n)
end
local function run(wsapi_env)
@norman
norman / object.lua
Created Apr 11, 2011
ridiculously simple object oriented Lua
View object.lua
local class = {}
local methods = {}
function class.new()
local instance = {}
return setmetatable(instance, {__index = methods})
end
return class