This file contains hidden or 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
// refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types | |
{ | |
".aac": "audio/aac", | |
".abw": "application/x-abiword", | |
".arc": "application/octet-stream", | |
".avi": "video/x-msvideo", | |
".azw": "application/vnd.amazon.ebook", | |
".bin": "application/octet-stream", | |
".bmp": "image/bmp", | |
".bz": "application/x-bzip", |
This file contains hidden or 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
from lib.errors import TypeConvertInvalid | |
SIMPLE_VALUE_TYPES = [str, int, float] | |
BOOLABLE_TYPES = SIMPLE_VALUE_TYPES[:] | |
BOOLABLE_TYPES.append(bool) | |
def convert(value, convert_func, parse_path, convertable_types=SIMPLE_VALUE_TYPES): | |
if type(value) in convertable_types: | |
try: | |
return convert_func(value) |
This file contains hidden or 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 collections | |
mydict = { | |
'a': 49023, | |
'b': 39201, | |
'c': 49021, | |
'd': 90201, | |
'e': 49012, | |
'f': 49401, | |
'g': 10039, |
This file contains hidden or 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
#!/usr/bin/env bash | |
NOT_GIT_REPO=1 | |
if $(git rev-list --all &>/dev/null) | |
then | |
echo "Detect git repo, continue now..." | |
else | |
echo "Could not find any git repo here!" | |
exit $NOT_GIT_REPO |
This file contains hidden or 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
hash1 = {a: 100, b: [1, 2], c: "hello"} | |
hash2 = {a: 300, b: [3, 4, 5], c: " world", d: "fh"} | |
hash1.merge(hash2) { |key, val_f, val_r| val_f + val_r } | |
# => {:a=>400, :b=>[1, 2, 3, 4, 5], :c=>"hello world", :d=>"fh"} |
This file contains hidden or 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
config.to_prepare do | |
# Load application's model / class decorators | |
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c| | |
Rails.configuration.cache_classes ? require(c) : load(c) | |
end | |
end |
This file contains hidden or 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
# generate factory with columns for model | |
# | |
# $ bundle exec rails g factory_girl:model User | |
require 'factory_girl' | |
require 'generators/factory_girl/model/model_generator' | |
FactoryGirl::Generators::ModelGenerator.class_eval do | |
alias :command_line_attributes :attributes |
This file contains hidden or 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
gem install nokogiri -v '1.7.0.1' -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-librarie |
This file contains hidden or 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 'openssl' | |
def hotp(secret, counter, digits = 6) | |
hash = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), secret, int_to_bytestring(counter)) | |
"%0#{digits}i" % (truncate(hash) % 10**digits) | |
end | |
def truncate(string) | |
offset = string.bytes.last & 0xf | |
partial = string.bytes[offset..offset+3] |
This file contains hidden or 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
/* use condition > */ | |
mysql> EXPLAIN SELECT * FROM test WHERE `test`.`activeday` > 10000 AND `test`.`deleted` = 0 ORDER BY id ASC LIMIT 20\G; | |
*************************** 1. row *************************** | |
possible_keys: index_on_test_to_activeday | |
key: PRIMARY | |
key_len: 4 | |
rows: 40 | |
filtered: 5.00 | |
Extra: Using where | |