Skip to content

Instantly share code, notes, and snippets.

View tjchambers's full-sized avatar

Tim Chambers tjchambers

View GitHub Profile
@tjchambers
tjchambers / csv_with_bom.rb
Created November 14, 2021 00:30 — forked from romeuhcf/csv_with_bom.rb
Ruby 2.5 support for opening csv with bom|utf-8
class CSV
def self.open(file, options={}, &block)
encoding = options.delete(:encoding)
File.open(file, "r:#{encoding}") do |fd|
yield CSV.new(fd, options)
end
end
end
@tjchambers
tjchambers / searcher.haml
Created July 17, 2017 18:38
haml for search
= javascript_include_tag 'searcher'
.text-right{ style: 'padding-bottom:14px;font-size:1.2em' }
.fa.fa-search.ico-place
%input{ style: '-webkit-appearance:searchfield;font-family: FontAwesome;',
type: 'search',
placeholder: 'Search ...',
onKeyUp: 'ds(this.value)',
onClick: 'ds(this.value)',
size: 27,
id: 'search_box' }
@tjchambers
tjchambers / searcher.haml
Created July 17, 2017 18:38
haml for search
= javascript_include_tag 'searcher'
.text-right{ style: 'padding-bottom:14px;font-size:1.2em' }
.fa.fa-search.ico-place
%input{ style: '-webkit-appearance:searchfield;font-family: FontAwesome;',
type: 'search',
placeholder: 'Search ...',
onKeyUp: 'ds(this.value)',
onClick: 'ds(this.value)',
size: 27,
id: 'search_box' }
/**
* Created by tj on 12/26/14.
*/
function ds(text) {
searchless(text);
$('.searchable').each(function () {
if (text.length < 2 || $(this).html().replace(/<\/?[^>]+>/gi, '|').search(r) >= 0) {
$(this).show();
} else {
@tjchambers
tjchambers / gist:e63fe9e13bef700614780d42f4e326ac
Last active March 10, 2017 23:14
RSpec query limit tests
# From http://stackoverflow.com/a/13423584/153896
module ActiveRecord
class QueryCounter
attr_reader :query_count
def initialize
@query_count = 0
end
def to_proc

Keybase proof

I hereby claim:

  • I am tjchambers on github.
  • I am tjchambers (https://keybase.io/tjchambers) on keybase.
  • I have a public key whose fingerprint is BD43 BA87 BEEC 388A E656 ED97 D35D C57D ABC0 60CA

To claim this, I am signing this object:

@tjchambers
tjchambers / mutant.rake
Created December 27, 2015 18:11
Runs mutant selectively
namespace :mutant do
MUTANT_VERSION = `mutant --version`.strip.split('-').last
def complete?(log)
content = File.read(log)
/Kills:/.match(content)
end
def preface(file, base)
@tjchambers
tjchambers / gist:fe58dd2a40117f97a2c2
Last active August 29, 2015 14:07
nginx.conf for kibana install
#
# Nginx proxy for Elasticsearch + Kibana
#
# In this setup, we are password protecting the saving of dashboards. You may
# wish to extend the password protection to all paths.
#
# Even though these paths are being called as the result of an ajax request, the
# browser will prompt for a username/password on the first request
#
# If you use this, you'll want to point config.js at http://FQDN:80/ instead of
@tjchambers
tjchambers / gist:717dde44ba5a2a295774
Created July 13, 2014 22:21
scrubber test for mutant
class EmailAddressScrubber
DUMMY = '@yahoo.com' unless defined?(DUMMY)
CANDIDATES = %w(TestingInferences.com CoordinationSystem.com DifficultConversation.com Undiscussible.com RelationshipEffectiveness.com Coordinated-Action.com OptimizeAlignment.com AlignmentOptimization.com) unless defined?(CANDIDATES)
def scrub(address)
x = address[1].ord % CANDIDATES.size
collapse(address.sub(DUMMY, "@#{CANDIDATES[x]}"))
end
@tjchambers
tjchambers / gist:7213479
Created October 29, 2013 12:07
Results running Dalli No Server available test
2.0.0-p195 :001 > require 'dalli'
=> true
2.0.0-p195 :002 >
2.0.0-p195 :003 > memcache ||= Dalli::Client.new
=> #<Dalli::Client:0x007fb753ccf210 @servers=["127.0.0.1:11211"], @options={}, @ring=nil>
2.0.0-p195 :004 > a = :dalli_store, '127.0.0.1',
2.0.0-p195 :005 > {:namespace => lambda {
2.0.0-p195 :006 > generation = $memcache.incr 'mv|' + Rails.env, 1, 0, 1
2.0.0-p195 :007?> "#{generation.to_s}.#{Time.now.strftime('%j')}"
2.0.0-p195 :008?> }}