Skip to content

Instantly share code, notes, and snippets.

View jemminger's full-sized avatar

Jeff Emminger jemminger

  • Seventh Compass
  • Florida
View GitHub Profile
@jemminger
jemminger / psql_naturalsort
Created October 24, 2018 16:33 — forked from veob/psql_naturalsort
PostgreSQL natural sort
//sql
create or replace function naturalsort(text)
returns bytea language sql immutable strict as
$f$ select string_agg(convert_to(coalesce(r[2],length(length(r[1])::text) || length(r[1])::text || r[1]),'SQL_ASCII'),'\x00')
from regexp_matches($1, '0*([0-9]+)|([^0-9]+)', 'g') r; $f$;
//author: github.com/RhodiumToad
@jemminger
jemminger / active_record_gem_failing.rb
Created October 24, 2017 03:59
ActiveRecord bug with unscope() and a grouped RH side
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jemminger
jemminger / github.svg
Last active September 12, 2017 23:49
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
// app/assets/javascripts/check_after_sign_in.js
$(function(){
if (Cookies.get("run_hubspot_stuff")){
// run the HS stuff
// clear out the cookie
Cookies.remove("run_hubspot_stuff");
}
@jemminger
jemminger / gist:5421979
Last active December 16, 2015 10:39
Benchmarking various implementations of the Fibonacci sequence, with and without memoization.
require 'benchmark'
module Memo
@@memo = { 0 => 0, 1 => 1 }
def memoize(method)
alias_method "old_#{method}".to_sym, method
define_method(method) do |*args|
@jemminger
jemminger / async.rb
Created July 2, 2011 14:25
Make any Ruby method asynchronous
# from http://stackoverflow.com/questions/6499654/is-there-an-asynchronous-logging-library-for-ruby/6527134#6527134
require 'thread'
require 'singleton'
require 'delegate'
require 'monitor'
class Async
include Singleton