Skip to content

Instantly share code, notes, and snippets.

@noahmatisoff
noahmatisoff / agg_query_builder.rb
Last active May 2, 2019 04:25
Filtered Aggregation + Query Builder
FILTERS = {
color: ['Black'],
make: ['Honda']
}.freeze
module Elasticsearch
MAPPING = { make: 'vehicle.make', color: 'vehicle.color' }.freeze
end
module Elasticsearch
@noahmatisoff
noahmatisoff / propEx.js
Last active December 11, 2015 19:30
Vue.js bind prop to prop
new Vue({
data: function() {
return {
field1: null,
field2: this.field1
}
}
})
class Hash
def to_xml(options = {})
require 'xmlsimple'
options.delete(:builder)
options.delete(:skip_instruct)
options.delete(:dasherize)
options.delete(:skip_types)
options[:Indent] = ' '*options.delete(:indent) unless options[:indent].nil?
options[:RootName] = options.delete(:root)
func GetGzip(path string) string {
println(path)
client := &http.Client{
Transport: &transport.Transport{
ReadTimeout: 10 * time.Second,
RequestTimeout: 15 * time.Second,
},
}

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
/*global Spinner*/
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['dw-spin-view'],
size: 'large',
sizes: {
@noahmatisoff
noahmatisoff / gist:2a8cb8db2a591c5e4c58
Created May 13, 2015 17:34
Ruby caller of method
caller[0][/`([^']*)'/, 1]
@noahmatisoff
noahmatisoff / gist:65fbd193e8df52bf6e4a
Created May 12, 2015 20:06
Pass parameters/options from a controller to an AMS.
# app/controllers/users_controller.rb
def show
@user = User.
render json: @user, winner: false, active: true
end
# app/serializers/user_serializer.rb
attributes :winner, :active
def winner
@noahmatisoff
noahmatisoff / gist:6147a4c71f564281730c
Last active August 29, 2015 14:19
Idempotent Stripe Charges
class StripeCharger
include Sidekiq::Worker
def perform(event, unique_job_key)
ActiveRecord::Base.connection_pool.with_connection do
token = event[:token]
txn = Transaction.find(event[:transaction_id])
begin
charge = Stripe::Charge.create({
@noahmatisoff
noahmatisoff / gist:03cc524bcc5084248a9e
Created March 23, 2015 21:09
Active Record self-referential one to one relationship
has_one :twin_model, class_name: "Model", foreign_key: :model_id
belongs_to :twin, class_name: "Model", foreign_key: :model_id