Skip to content

Instantly share code, notes, and snippets.

@tatey
tatey / 0_attribute_encrypted.rb
Last active August 21, 2018 22:28
AttributeEncrypted is a simple way to encrypt values in the database using the same mechanism as Rails credentials, including the master key.
# AttributeEncrypted is a simple way to encrypt values in the database
# using the same mechanism as Rails credentials, including the master key.
#
# Example:
# class User
# include AttributeEncrypted
#
# attr_accessor :encrypted_secret
# attr_encrypted :secret
# end
@tatey
tatey / equality.rb
Created August 2, 2018 11:37
What could possibly go wrong?
module Equality
def ==(other)
return false unless other.is_a?(self.class)
instance_variables.all? do |ivar|
instance_variable_get(ivar) == other.instance_variable_get(ivar)
end
end
end
fu$ yarn exec webpack-dev-server
yarn exec v1.3.2
warning package.json: No license field
module.js:544
throw err;
^
Error: Cannot find module './codes.json'
at Function.Module._resolveFilename (module.js:542:15)
at Function.Module._load (module.js:472:25)
@tatey
tatey / benchmark.rb
Created February 20, 2012 22:11
Mocha VS MiniTest::Mock and SimpleDelegate VS SimpleMock
require 'benchmark'
require 'delegate'
require 'mocha'
require 'simple_mock'
Benchmark.bm(10000) do |x|
x.report :mocha do
array = [1]
array.expects(:push).with(2).returns([1, 2])
array.push(2)
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface ErrorFormatter : NSObject
@property (strong, nonatomic) NSError *error;
- (id)initWithError:(NSError *)error;
- (UIAlertView *)alert;
crystal(test)$ bin/crystal spec spec/std/socket_spec.cr
clang: error: no such file or directory: '/Users/Tate/Code/manastech/crystal/src/ext/libcrystal.a'
Error: execution of command failed with code: 1: `cc -o "/Users/Tate/Code/manastech/crystal/.crystal/crystal-run-spec.tmp" "${@}" -rdynamic /Users/Tate/Code/manastech/crystal/src/ext/libcrystal.a -levent -lpcre -lgc -lpthread -ldl`
We couldn’t find that file to show.
@tatey
tatey / es_index_conflict_mapping
Last active January 28, 2016 06:19
Identify conflicting field mappings in ElasticSearch 1.x > 2.0 upgrade
#!/usr/bin/env ruby
require 'json'
if ARGV.size < 1
puts "usage: #{__FILE__} <FILE1> [FILE2 ...]"
puts " eg: ./es_index_conflict_mapping applogs-2016.01.10.json applogs-2016.01.13.json applogs-2016.01.08.json applogs-2016.01.11.json applogs-2016.01.27.json"
abort
end
@tatey
tatey / class.js
Last active January 4, 2016 21:09
TimeRange.prototype.getEnd = function() {
var end = this.end;
if (end) {
return end;
} else {
return parseInt(this.start) + 3600 // 1 hour
}
};