Skip to content

Instantly share code, notes, and snippets.

View norman's full-sized avatar
🪕
Scruggs not drugs

Norman Clarke norman

🪕
Scruggs not drugs
View GitHub Profile
@norman
norman / earthdistance.rb
Last active May 10, 2026 18:08
Geographic Searches With Postgres's Earthdistance and Cube Extensions
#!/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 / pg.txt
Last active October 28, 2024 11:35
Optimal development-only Postgres settings for my Macbook Pro with 8GB RAM.
#------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------
# Add settings for extensions here
#
# Some stupid, dangerous settings only used to speed things up on a local
# development machine, where if data is lost I'll just wipe and recreate.
# Never ever ever use these in production or anything approximating
# production.
strings = %w[aa áb ac na ña ne oa]
# Provide alphabetical sort in Spanish, where accented vowels are sorted
# the same as unaccented vowels, and "ñ" is sorted directly after "n".
#
# This is accomplished by normalizing the string to Unicode decomposed form
# to break characters with diacritics into multiple characters, and then
# removing acute accents and diaresis: e.g. "á" becomes "a", "ü" becomes
# "u". These are the only two diacritics used for vowels in Spanish.
#
@norman
norman / fixtures_spec.rb
Created October 13, 2021 13:59
Test the validity of your Rails fixtures
# 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 / character_reference.rb
Last active September 9, 2021 20:48
HTML entities? We don't need no stinkin' HTML entities.
# 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 September 4, 2011 02:33
string interpolation vs array join
require "benchmark"
puts %x{ruby -v} + "\n"
Benchmark.bmbm do |x|
N = 1_000_000
a = "aa"
b = "bb"
!!!
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 November 21, 2019 11:58
Delayed Job without Rails
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 16:05
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
@norman
norman / keybase.md
Created March 22, 2018 13:08
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: