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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Simple Radar Chart</title>
<link rel="stylesheet" href="style.css"/>
<script src="http://mbostock.github.com/d3/d3.js?2.5.0"></script>
<script src="radar.js"></script>
</head><body><h1>Simple Radar Chart</h1>
<div id="viz">
</div>
@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: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?> }}
@tjchambers
tjchambers / Dalli down error
Created October 29, 2013 12:05
Code to create dalli down error
require 'dalli'
memcache ||= Dalli::Client.new
a = :dalli_store, '127.0.0.1',
{:namespace => lambda {
generation = $memcache.incr 'mv|' + Rails.env, 1, 0, 1
"#{generation.to_s}.#{Time.now.strftime('%j')}"
}}
memcache.incr 'test',0,0,0