Skip to content

Instantly share code, notes, and snippets.

View ianks's full-sized avatar

Ian Ker-Seymer ianks

View GitHub Profile
@ianks
ianks / tasks.json
Created September 16, 2016 22:02
Mocha tasks.js for vscode with problemMatcher
{
"version": "0.1.0",
"command": "mocha",
"isShellCommand": true,
"showOutput": "silent",
"args": [
"--require",
"test/inject.js",
"--reporter",
"tap",
ATTRIBUTE_NODE
CDATA_SECTION_NODE
COMMENT_NODE
DOCUMENT_FRAGMENT_NODE
DOCUMENT_NODE
DOCUMENT_POSITION_CONTAINED_BY
DOCUMENT_POSITION_CONTAINS
DOCUMENT_POSITION_DISCONNECTED
DOCUMENT_POSITION_FOLLOWING
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
=== Benchmarking resource with associations ======
Calculating -------------------------------------
attributes 442.000 i/100ms
json 367.000 i/100ms
json_api 248.000 i/100ms
-------------------------------------------------
attributes 4.614k (± 0.9%) i/s - 23.426k
json 3.811k (± 0.7%) i/s - 19.084k
json_api 2.534k (± 0.8%) i/s - 12.896k
@ianks
ianks / genericDecorator.ts
Created January 6, 2016 16:11
Generic method decorator Typescript
// In this example, I am trying to have a user specify a type for generic decorator function fetchJson.
//
// It would work like this:
// 1. call to `@fetchJson<User>`
// 2. We then replace the function with one that automatically calls `.then(res => res.json())`, and give back
// a typed value in a Promise,
//
// This issue I am running into is that I do not know how to assign the return `descriptor.value` to a user-assigned T.
// Is there a better way to do this? I feel like I am missing something entirely.
// What will be printed to stdout after executing the following
// JavaScript? Describe how you arrived at this answer.
var x = 5;
setTimeout(function() {
console.log(x++);
}, 3000);
#<CampaignStat:0x00556d0ec115a8
  id: 11333,
  campaign_id: 415,
  date: Sat, 20 Jun 2015,
  year: 2015,
  month: 6,
  day: 20,
  metric: "clicks",
 value: 0,
I, [2015-07-23T15:20:32.590899 #6098] INFO -- : Loading Rails (4.2.3) integration
I, [2015-07-23T15:20:33.655093 #6098] INFO -- : Starting AppSignal 0.11.9 on 2.2.2/x86_64-linux
I, [2015-07-23T15:20:33.661520 #6098] INFO -- : Loading Sidekiq integration
I, [2015-07-23T15:20:33.665146 #6098] INFO -- : Started Appsignal agent
I, [2015-07-23T15:20:38.967494 #6107] INFO -- : Forked worker process
E, [2015-07-23T15:20:38.968280 #6107] ERROR -- : NoMethodError while sending queue: undefined method `message' for "testdfasdfasdf":String
/home/ianks/.gem/ruby/2.2.2/gems/appsignal-0.11.9/lib/appsignal/transaction/formatter.rb:65:in `add_exception_to_hash!'
/home/ianks/.gem/ruby/2.2.2/gems/appsignal-0.11.9/lib/appsignal/transaction/formatter.rb:14:in `to_hash'
/home/ianks/.gem/ruby/2.2.2/gems/appsignal-0.11.9/lib/appsignal/transaction.rb:151:in `to_hash'
/home/ianks/.gem/ruby/2.2.2/gems/appsignal-0.11.9/lib/appsignal/aggregator/post_processor.rb:15:in `block in post_processed_queue!'
@ianks
ianks / factory_girl_translate.md
Last active August 29, 2015 14:25
Generate FactoryGirl factories from models

I wanted to be able to auto-generate FactoryGirl factories from my database, so this task will do that, using Faker to give you fake data.

require 'erb'

task :factory_girl_translate, [:model] => [:environment] do |t, args|
  puts FactoryTemplate.new(model: args[:model]).render
end

class FactoryTemplate
  def initialize(model:)
#!/usr/bin/env ruby
require 'benchmark'
class StateClass
def initialize(value, mark)
@value, @mark = value, mark
end
end
loop do
who, mark = @owner.get
end while mark && who != me