This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "net/ftp" | |
require "miro" | |
class HexBuilder | |
attr_accessor :url_or_path, :local | |
def self.call(url_or_path, opts = {}) | |
new(url_or_path, opts).call | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
require 'benchmark' | |
require 'bigdecimal/math' | |
class Hash | |
def to_struct | |
Struct.new(*(k = self.keys)).new(*self.values_at(*k)) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
require 'benchmark' | |
require 'bigdecimal/math' | |
class Hash | |
def to_struct | |
k = self.keys | |
klass = k.map(&:to_s).sort_by {|word| word.downcase}.join.capitalize | |
begin | |
Kernel.const_get("Struct::" + klass).new(*self.values_at(*k)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# What I want to do is take a string like "some_attribute <= 5" and be able to parse that into SQL | |
# The string will only ever have one operation so I need to check for the inclusion of any valid opperator | |
# and build a SQL string based on that. | |
# initial conditional method | |
def build_sql_string | |
@final_sql_array = sql_array.map(&:strip).map do |string| | |
if string.include?(":") | |
q = string.split(":") | |
"(similarity((data->>'#{q[0].strip}')::text, '#{q[1].strip}') > .5 OR " + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App.Logger | |
@add_error: (error_object) -> | |
@error ||= [] | |
@error.push(error_object) | |
jQueryInit = $.fn.init | |
$.fn.init = (selector, context) -> | |
element = new jQueryInit(selector, context) | |
if selector and element.length is 0 | |
# must include stacktrace library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monkey patch for ActiveRecord::Base to return serialized JSON in the format | |
# of an ActiveModel::Serializer. | |
module SerializedJson | |
extend ActiveSupport::Concern | |
def to_serial(serializer=nil, opts={}) | |
if self.respond_to?(:map) | |
serializer ||= (self.base_class.name + "Serializer").constantize | |
serialized_collection = self.map do |resource| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MoneyRails.configure do |config| | |
config.register_currency = { | |
:priority => 1, | |
:iso_code => "USD1", | |
:name => "USD with subunit of 4 digits", | |
:symbol => "$", | |
:symbol_first => true, | |
:subunit => "Subcent", | |
:subunit_to_unit => 10000, | |
:thousands_separator => ",", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
var Pollable = Ember.Mixin.create({ | |
afterModel: function (model, transition) { | |
var self = this; | |
this._super(model, transition); | |
var interval_info = this.get('interval_info'); | |
if (!interval_info) { | |
interval_info = Ember.Object.create({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
guard "minitest", all_on_start: false, start_on_start: false do | |
# with Minitest::Spec | |
watch(%r|^test/(.*)_test\.rb$|) | |
watch(%r|^app/(.*)/(.*)\.rb$|) { |m| "test/#{m[1]}/#{m[2]}_test.rb" } | |
watch(%r|^lib/(.*)([^/]+)\.rb$|) { |m| "test/#{m[1]}#{m[2]}_test.rb" } | |
watch(%r|^test/test_helper\.rb$|) { "test" } | |
watch(%r|^test/support/|) { "test" } | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#minitest/spec | |
# Drop SOLO in the name of the test you want to run and then run | |
# solo and tab complete the path/to/the/test/file.rb | |
solo() { | |
ruby -Itest $1 --name /SOLO/ | |
} | |
# describe SomeClass do | |
# it "does some stuff SOLO" do |
OlderNewer