Skip to content

Instantly share code, notes, and snippets.

View brandonc's full-sized avatar
⚙️

Brandon Croft brandonc

⚙️
View GitHub Profile
@brandonc
brandonc / vscodesettings.json
Created August 9, 2018 16:54
vscodesettings.json
{
"editor.dragAndDrop": false,
"editor.fontFamily": "'IBM Plex Mono Light'",
"editor.lineHeight": 20,
"editor.minimap.enabled": false,
"editor.renderIndentGuides": false,
"editor.roundedSelection": false,
"editor.rulers": [100, 120],
"editor.tabSize": 2,
"files.trimTrailingWhitespace": true,
@brandonc
brandonc / vim-heroku.sh
Last active November 16, 2017 17:08 — forked from dvdbng/vim-heroku.sh
Run vim in heroku updated 2017
# Staically linked vim version compiled from https://github.com/ericpruitt/static-vim
# Compiled on Jul 20 2017
mkdir ~/vim && cd ~/vim && curl 'https://s3.amazonaws.com/bengoa/vim-static.tar.gz' | tar -xz && export VIMRUNTIME="$HOME/vim/runtime" && export PATH="$HOME/vim:$PATH" && cd -
@brandonc
brandonc / batch_job_stateful.rb
Created February 18, 2016 23:05
Attach batch progress tracking to a model via concern
module BatchJobStateful
extend ActiveSupport::Concern
included do
field :current_batch_id, type: String
field :last_batch_total, type: Integer
field :last_batch_failures, type: Integer
field :last_batch_created_at, type: Time
field :last_batch_completed_at, type: Time
end
module Mongoid
# Mongoid extension which stores all fetched records in a memory cache
module TimestampCacheable
extend ActiveSupport::Concern
class QueryNotCacheableError < StandardError; end
module ClassMethods
def queryable
scope_stack.last || TimestampCacheableCriteria.new(self)
CoffeeScript JS
Single Quotes ? Never
Double Quotes Always
@brandonc
brandonc / collection.coffee
Created December 5, 2014 20:03
Module pattern in Coffeescript
class MyCollection extends Backbone.Collection
classExtend(@, ModuleCollectionAsOptions)
# works
new MyCollection().toOptionsJSON()
class String
def self.similarity(a, b)
if a == b
return a.length
end
result = 0
while a[result] == b[result]
result += 1
end
"custom_fields": [
{
"id": "513fba45deeed40200000250",
"field_type": "select",
"display_label": "Primary CTA",
"name": "primary call to action",
"created_at": "2013-03-12T23:29:10Z",
"select_values": [
"Read More",
"Subscribe",
@brandonc
brandonc / webhooks_sample.json
Last active December 23, 2015 00:49
Webhooks sample payload
{
"operation":"create",
"type":"content",
"payload":{
"full_post":{
"id":"523381424aaaaecc80000001",
"idea_title":null,
"content_title":null,
"creator_id":"51e477b9e1f419ecf4000004",
"assignee_id":"51e477b9e1f419ecf4000004",
@brandonc
brandonc / success.rb
Created August 2, 2013 17:45
Generate a compound success message
def create_success_message
result = @created_events.reduce("Post updated,") do |m, ev|
case ev.class
when PostAssignedEvent
m += " assigned to #{ev.assignee.name},"
when PostArchivedEvent
m += " archived,"
when PostUnassignedEvent
m += " assigned user cleared,"
when PostProposedEvent