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
def diff(one, other) | |
(one.keys + other.keys).uniq.inject({}) do |memo, key| | |
unless one.key?(key) && other.key?(key) && one[key] == other[key] | |
memo[key] = [one.key?(key) ? one[key] : :_no_key, other.key?(key) ? other[key] : :_no_key] | |
end | |
memo | |
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
require 'mongo' | |
primary = Mongo::MongoClient.from_uri('mongodb://nbuild:<password>@mongo3.nbuild.prd.atl.3dna.io/nbuild') | |
primary_collection = primary['nbuild']['oauth_access_tokens'] | |
primary_collection.count # => 203 | |
slave = Mongo::MongoClient.from_uri('mongodb://nbuild:<password>@mongo-delayed.nbuild.prd.atl.3dna.io/nbuild?slaveok=true') | |
slave_collection = slave['nbuild']['oauth_access_tokens'] | |
slave_collection.count # => 128481 |
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
# A few examples about how to use Ruby for parsing files as we could do | |
# with Awk or Grep. This is based on what I learn fro this post: | |
# http://code.joejag.com/2009/using-ruby-as-an-awk-replacement/ | |
# Split each line with ':' and print the first $F[0] field | |
awk -F: '{ print $1 }' /etc/passwd | |
ruby -F: -nae 'puts $F[0]' /etc/passwd | |
# Parse the 'ps aux' output | |
# It'll print the ID process for the 'jojeda' user |
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
def self.process_results(num) | |
client.process_results(num) do |address_hash| # Redis LPOP and a JSON parse should be fast | |
Nation.with(address_hash['passthrough']['nation_slug']) do # Is Nation.with slow??? | |
address = Address.find_by_id(address_hash['passthrough']['address_id']) # find_by_id is should be fast | |
next unless address | |
begin | |
address.update_geocode_data(address_hash) # Is update_geocode_data slow? | |
rescue ActiveRecord::RecordInvalid |
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 'charlock_holmes' | |
def is_utf8?(data) | |
data.force_encoding('UTF-8').valid_encoding? | |
end | |
def detect_with_charlock_holmes(data) | |
detection = CharlockHolmes::EncodingDetector.detect(data) | |
return detection[:encoding] | |
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
Show hidden characters
{ | |
"auto_complete": false, | |
"color_scheme": "Packages/Theme - Flatland/Flatland Monokai.tmTheme", | |
"font_size": 16, | |
"ignored_packages": | |
[ | |
], | |
"ruby_eval": | |
{ | |
"ruby": "/Users/nbdev/.rvm/rubies/ruby-1.9.3-p327/bin/ruby" |
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
[ | |
// bind 'jj' to exit insert mode | |
{ "keys": ["j", "j"], "command": "exit_insert_mode", | |
"context": | |
[ | |
{ "key": "setting.command_mode", "operand": false }, | |
{ "key": "setting.is_widget", "operand": false } | |
] | |
}, |
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 ruby | |
require 'nokogiri' | |
require 'github/markup' | |
def preformatted_html | |
file = ARGV.first | |
GitHub::Markup.render(file, File.read(file)) | |
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
#!/bin/bash | |
# nuke-dbs -- completely restore nbuild databases | |
cd $NBUILD | |
# Note: This script assumes that your checkout of nbuild is | |
# in ~/Workspace/nbuild. | |
# Exit if errors are encountered |
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
cat temp.txt | ruby -ne 's ||= 0.0; s += $_.to_f; puts s' |