Skip to content

Instantly share code, notes, and snippets.

View whatcould's full-sized avatar

David Reese whatcould

  • Bust Out Solutions
  • philly
View GitHub Profile
@whatcould
whatcould / analytics.rb
Last active August 29, 2015 14:07 — forked from joshuaclayton/README.md
RSpec custom matchers for Segment.io tracking
RSpec::Matchers.define :have_tracked do |event_name|
match do |backend|
@event_name = event_name
@backend = backend
if @match_user && @properties
backend.tracked_events_for(@match_user).named(@event_name).has_properties?(@properties)
elsif @properties
backend.tracked_events.named(@event_name).has_properties?(@properties)
elsif @match_user
backend.tracked_events_for(@match_user).named(@event_name).events.any?
@whatcould
whatcould / albers.html
Last active August 29, 2015 14:14 — forked from minikomi/albers.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Albers Projection</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/2.8.1/d3.v2.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style type="text/css">
@whatcould
whatcould / gist:5a7c6c28e757544744e4
Last active August 29, 2015 14:27 — forked from heijmerikx/gist:1261118
MySQL FIND_IN_SET to Postgresql...
def self.order(ids)
# The postgresql way
update_all(["position = STRPOS(?, ','||id||',')", ",#{ids.join(',')},"])
# the mysql way
# update_all(['position = FIND_IN_SET(id, ?)', ids.join(',')])
end
@whatcould
whatcould / current_zone_memory
Created January 19, 2009 19:39
munin plugin to track memory on solaris zone (joyent accelerator)
#!/usr/bin/env ruby
def output_config
puts <<-END
graph_category System
graph_title accelerator memory
graph_vlabel M
rss.label rss
swap.label swap
@whatcould
whatcould / .autotest
Created February 9, 2009 23:57
.autotest your engine plugins with your main app
# autotest your engine plugins together with your rails app
# put this .autotest file in your rails root
# see http://code.whatcould.com/2009/02/09/gentlemen-test-your-engines.html for details
# iirc, I submitted a pull request to zentest but never heard back.
# so you'll have to use my zentest fork -- I've been trying to keep it up.
# https://github.com/whatcould/zentest -- just build the gem (rake package) and install from that file
# rewrite the Autotest::Rails #path_to_classname to include the entire test path
# cache read benchmark (about a 2k string)
# I get the actual memcache store from ActionController
cache = ActionController::Caching.send(:class_variable_get,:@@cache_store)
# and run the benchmark 100 times
ActionController::Base.benchmark "cache benchmark: " do
100.times do
cache.read('views/sightings/1624/row')
end
testing ActiveSupport::Cache with different versions of memcache_client:
see test in http://gist.github.com/94481
memcache_client version: 1.5.0
7.610000 0.510000 8.120000 ( 9.603848)
memcache_client version: 1.5.0.1
8.010000 0.490000 8.500000 ( 9.738587)
memcache_client version: 1.5.0.5
require 'abstract_unit'
require 'benchmark'
class MemcacheClientTest < Test::Unit::TestCase
def setup
@cache_store = ActiveSupport::Cache.lookup_store(:mem_cache_store, "127.0.0.1:11211", "localhost:11211")
@cache_store_no_timeouts = ActiveSupport::Cache.lookup_store(:mem_cache_store,"127.0.0.1:11211", "localhost:11211",{ :timeout => nil })
@test_string = "A short string, but not too short; an average-length string, let's say. Just a little more length. Ok, now we're about right."
@test_string_2 = "73f382c327d2fb5809f383fca29b1fa8a9931b3d316836ad8598cdb1f7105a4d98296238a451122b340259ffb0b9b5e517d8d315244fe917e3a114c5d5a367f3"
<div class="primary_fields">
{{ form.list }}
{{ form.name }}
{{ form.description }}
{{ form.url }}
</div>
# etc
And each of the form.fieldname lines (whatever the markup would be) would be doing something like this, but maybe with real code instead of the template language:
@whatcould
whatcould / liquid.js
Created November 9, 2009 02:06
Liquid-template language definition for codepress (http://codepress.sourceforge.net/)
/*
* CodePress regular expressions for HTML syntax highlighting
*/
// HTML
Language.syntax = [
{ input : /(&lt;[^!]*?&gt;)/g, output : '<b>$1</b>' }, // all tags
{ input : /(&lt;a .*?&gt;|&lt;\/a&gt;)/g, output : '<a>$1</a>' }, // links
{ input : /(&lt;img .*?&gt;)/g, output : '<big>$1</big>' }, // images
{ input : /(&lt;\/?(button|textarea|form|input|select|option|label).*?&gt;)/g, output : '<u>$1</u>' }, // forms