Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
jnunemaker / application.js
Created March 3, 2010 18:43 — forked from bkeepers/application.js
browser cookie timezone stuff
jQuery(function() {
$.cookie('tz', (new Date()).getTimezoneOffset());
});
@jnunemaker
jnunemaker / gist:841656
Created February 24, 2011 02:38
all time views across system for http://gaug.es
# How we store all time views across the entire system for http://gauge.es.
# All in one document that gets incremented using MongoDB $inc modifier in
# every track. The $inc increments t, year.t, year.month.t, year.month.day.t
# so we get to the day numbers. These are in EST, as we are in EST and these
# stats are just for us. :) Nothing amazing, but thought I would share.
#
# >> pp View.all_time
{
"_id" => "all_time",
"t" => 502352,
@jnunemaker
jnunemaker / stylesheet.rb
Created May 17, 2010 22:16
stripped down version of processors in the stylesheet model in harmonyapp.com
class Stylesheet
include MongoMapper::Document
class Processor
def self.errors
[]
end
attr_reader :contents
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:atom="http://www.w3.org/2005/Atom/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://podcastindex.org/namespace/1.0" xmlns:fireside="https://fireside.fm/modules/rss/fireside" version="2.0" encoding="UTF-8">
<channel>
<fireside:hostname>feed03.fireside.fm</fireside:hostname>
<fireside:genDate>Mon, 15 Dec 2025 02:46:05 -0600</fireside:genDate>
<generator>Fireside (https://fireside.fm)</generator>
<title>The Bible in a Year (with Fr. Mike Schmitz)</title>
<link>https://bibleinayear.fireside.fm</link>
<pubDate>Mon, 15 Dec 2025 03:45:05 -0500</pubDate>
<description>In The Bible in a Year podca
@jnunemaker
jnunemaker / github_sql_patches.rb
Last active June 6, 2025 19:23
Hack GitHub sql to work with postgres cast operator
# Shorcut because typing GitHub everywhere gets old
SQL = GitHub::SQL
module GitHub
class SQL
private
# Overwrite interpolate to be ok with postgres casting (::regclass, etc.).
def interpolate(sql, extras = nil)
sql.gsub(/(:?):([a-z][a-z0-9_]*)/) do |match|
@jnunemaker
jnunemaker / partition_by_day.rb
Created December 2, 2021 19:42
Ruby class to partition by day using native declarative partitioning in postgres
# https://www.postgresql.org/docs/13/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE
class PartitionByDay
class Row
include Virtus.model
attribute :name, String
attribute :expression, String
end
def self.all(table)
@jnunemaker
jnunemaker / gist:4495290
Created January 9, 2013 18:00
Web And Mobile Revenue Models
@jnunemaker
jnunemaker / database.yml
Created November 12, 2009 14:59
mongo initializer to load config from database.yml, authenticate if needed and ensure indexes are created
development: &global_settings
database: textual_development
host: 127.0.0.1
port: 27017
test:
database: textual_test
<<: *global_settings
production:
@jnunemaker
jnunemaker / active_job_checkins.rb
Created September 28, 2023 14:31
Automatic honey badger check ins for active job. Just setup the check in with honey badger and configure an env var to the identifier they provide.
# Set HONEYBADGER_FOO_BAR_JOB=asdf where asdf is the check in value Honeybadger gives you.
class ApplicationJob < ActiveJob::Base
after_perform { |job| job.honeybadger_checkin }
# Check in with Honeybadger to let us know that the job was performed
# if there is an identifier configured for the job.
def honeybadger_checkin
identifier = honeybadger_checkin_identifier
return unless identifier.present?
@jnunemaker
jnunemaker / levenshtein.sql
Created September 11, 2023 13:02
Some example usage of levenshtein to calculate the difference between two strings.
-- https://www.postgresql.org/docs/current/fuzzystrmatch.html#id-1.11.7.26.7
-- Calculates the distance between two strings.
SELECT levenshtein('New York', 'New York'); -- 0
SELECT levenshtein('New York', 'New Jersey'); -- 5
SELECT levenshtein('New York', 'Dallas'); -- 8
-- find the opponent with the name closest to 'New York'
SELECT * FROM opponents WHERE team_id = 1
ORDER BY levenshtein(name, 'New York')