Skip to content

Instantly share code, notes, and snippets.

View Narnach's full-sized avatar

Wes Oldenbeuving Narnach

View GitHub Profile
@Narnach
Narnach / appsignal.cap
Created March 7, 2014 13:05
Appsignal capistrano 3 recipe
# lib/capistrano/tasks/appsignal.cap
require 'appsignal'
require 'appsignal/marker'
namespace :appsignal do
task :deploy do
env = fetch(:rails_env, fetch(:rack_env, 'production'))
user = ENV['USER'] || ENV['USERNAME']

Keybase proof

I hereby claim:

  • I am Narnach on github.
  • I am narnach (https://keybase.io/narnach) on keybase.
  • I have a public key whose fingerprint is 7655 6328 F92B 8BAC 788C DB71 AF8B 92CD AB84 DCD1

To claim this, I am signing this object:

@Narnach
Narnach / session.rb
Last active August 29, 2015 13:57
A more efficient way to store data in the DB than the default approach of doing a raw Base64 on the Marshal-ed version of a session hash.
# Add this to your Gemfile:
#
# # Session store built on top of ActiveRecord
# gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
# # C-based parser backend for multi_json
# gem 'oj'
# # Unified API for parsing JSON
# gem 'multi_json'
#
class Session < ActiveRecord::SessionStore::Session
@Narnach
Narnach / gist:10017973
Created April 7, 2014 10:32
Spotify console log
07/04/14 12:28:14,229 Spotify Helper[3900]: Internals of CFAllocator not known; out-of-memory failures via CFAllocator will not result in termination. http://crbug.com/45650
07/04/14 12:28:14,353 Spotify Helper[3900]: The function `CGFontSetShouldUseMulticache' is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance.
07/04/14 12:28:44,031 Spotify Helper[3903]: Internals of CFAllocator not known; out-of-memory failures via CFAllocator will not result in termination. http://crbug.com/45650
07/04/14 12:28:44,293 Spotify Helper[3903]: The function `CGFontSetShouldUseMulticache' is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance.
@Narnach
Narnach / application.rb
Created July 16, 2014 09:57
Simple memory usage counter which diffs vs the last call. Built for rails, but can work anywhere.
# Add this to the very TOP of config/application.rb, before the first statement
require 'pp'
module OSCount
def self.count(msg, force_count: false)
return if ENV['RAILS_ENV'] == 'test'
count = ObjectSpace.count_objects
last_count = Thread.current['OSCount.last_count']
Thread.current['OSCount.last_count'] = count
show_count = last_count.nil?
show_count = true if force_count
# This is motivated/inspired by Avdi Grimm's post on Boolean Externalties
#
# http://devblog.avdi.org/2014/09/17/boolean-externalities/
#
# In his post he asks the question: if a predicate returns false, why does it do so?
# If you chain a lot of predicates, it's hard to figure out why you get the answer you get. Consider this example:
# This implements some simple chained predicate logic to determine if the object is scary.
class SimpleBoo
def scary?
@Narnach
Narnach / gist:ad9e4243f1799b273f4d
Created December 2, 2014 12:26
Rubymine 7.0.1 startup error
[ 2820] WARN - om.intellij.util.ProfilingUtil - YourKit controller initialization failed
java.lang.Exception: To profile application, you should run it with the profiler agent
at com.yourkit.api.Controller.getUsedPort(Controller.java:158)
at com.yourkit.api.Controller.<init>(Controller.java:83)
at com.intellij.util.ProfilingUtil.<clinit>(ProfilingUtil.java:57)
at com.intellij.util.CaptureMemorySnapshotAction.update(CaptureMemorySnapshotAction.java:25)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:113)
at com.intellij.openapi.actionSystem.impl.Utils.a(Utils.java:188)
at com.intellij.openapi.actionSystem.impl.Utils.expandActionGroup(Utils.java:139)
at com.intellij.openapi.actionSystem.impl.Utils.expandActionGroup(Utils.java:164)
@Narnach
Narnach / gist:15b173f85fceace81112
Created January 27, 2015 15:12
Capistrano stats... WTF?
$ cap production deploy
DEBUG [26af543f] Running /usr/bin/env [ ! -d /usr/local/rbenv/versions/2.1.5 ] as user@example.org
DEBUG [26af543f] Command: [ ! -d /usr/local/rbenv/versions/2.1.5 ]
DEBUG [26af543f] Finished in 1.506 seconds with exit status 1 (failed).
Would you like to enable statistics? Here is an example message we would
send:
1|2015-01-27T16:10:07+01:00|2.1.5|x86_64-darwin14.0|3.3.5|ef0abd3f
Do you want to enable statistics? (y/N):
@Narnach
Narnach / get_mcc_mnc.rb
Last active August 29, 2015 14:26 — forked from choonkeat/get_mcc_mnc.rb
mcc mnc data from wikipedia
#!/usr/bin/env ruby
# Based on https://gist.github.com/choonkeat/4277277
#
# Not sure what the deal was with all that SSL stuff in there, but it was the cause content fetching did not work.
# Replaced it with plain old open-uri and it just works.
require 'net/https'
require 'open-uri'
require 'nokogiri'
require 'json'
@Narnach
Narnach / gist:21324
Created October 31, 2008 15:08
Use a Module to overwrite a method
#!/usr/bin/env ruby
# Goal:
# I want to overwrite an existing method on a class by using a module,
# instead of opening up the class and overwriting the method.
#
# Problem:
# Modules are treated kinda like a superclass.
# This means you can't use it to override a method,
# because it lies further away in the method call chain.
#