Skip to content

Instantly share code, notes, and snippets.

@bdunagan
bdunagan / gtalk-jabber-subscribe.rb
Created Oct 29, 2011
Invite users from Google Talk using Ruby and Jabber
View gtalk-jabber-subscribe.rb
# https://github.com/ln/xmpp4r
# gem install xmpp4r
require 'xmpp4r'
email = ADD_EMAIL
password = ADD_PASSWORD
friends_email = ADD_EMAIL
client = Jabber::Client::new(Jabber::JID::new(email))
client.connect("talk.google.com")
client.auth(password)
client.send(Jabber::Presence.new.set_type(:subscribe).set_to(friends_email))
View gist:1325096
# Outside screen
screen # Start screen.
screen -ls # List sessions.
screen -r id # Reattach to session.
screen -h # Help.
# Inside screen
Ctrl+a " # List sessions
Ctrl+a d # Detach session.
Ctrl+a ? # Help.
@bdunagan
bdunagan / git.log.with.lines.changed.rb
Created Nov 13, 2011
git log with colors and lines changed
View git.log.with.lines.changed.rb
# See colored 'git log' with lines changes in Terminal on Mac
# => * 1234567 - 2001-01-01 - NNNNN - description <user>
# Based on http://www.jukie.net/bart/blog/pimping-out-git-log
# git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
# To install as 'gl' alias (not overriding 'git log'):
# 1) save this as ~/.gitlog.rb
# 2) add to ~/.bash_profile: 'alias gl="ruby ~/.gitlog.rb | more -r"'
@bdunagan
bdunagan / s3-delete-bucket.rb
Created Nov 21, 2011
s3-delete-bucket.rb: quickly delete large AWS S3 buckets using fog
View s3-delete-bucket.rb
#!/usr/bin/env ruby
# s3-delete-bucket.rb
# Fog-based script for deleting large Amazon AWS S3 buckets (~100 files/second)
# Forked from this excellent script: https://github.com/SFEley/s3nuke
require 'rubygems'
require 'thread'
require 'fog'
View missing_keys.rb
# models/missing_keys.rb
class MissingKeys
def initialize(backend)
@backend = backend
self.load_config
self.load_translations
end
# Returns an array with all keys from all locales
View missing_keys_controller.rb
# routes.rb
get '/missing_keys', :to => 'home#missing_keys'
# home_controller.rb
def missing_keys
finder = MissingKeys.new(I18n.backend)
@all_keys = finder.all_keys
@missing_keys = finder.find_missing_keys
@found_keys = @all_keys.collect { |key| key unless @missing_keys.keys.include?(key) }.compact
View missing_keys.html.erb
# views/home/missing_keys.html.erb
<h1>Localization</h1>
<ul>
<li><%= link_to "Unlocalized", "#unlocalized" %></li>
<li><%= link_to "Localized", "#localized" %></li>
</ul>
<h2 id="unlocalized">Unlocalized: <%= @missing_keys.count %> missing out of <%= @missing_keys.count + @found_keys.count %></h2>
<ul style="list-style:none; line-height:22px; margin-left:-40px">
<% @missing_keys.each do |key, value| %>
View youtube-api-v3.rb
# List of all uploaded videos and playlists on a YouTube Channel
# Note that YouTube API v3 requires a key. Create a browser API key with a referer at https://console.developers.google.com.
#
# Here are the steps using "curl" that matches the Ruby code below:
#
# Get channel information.
# curl --referer "YOUR_REFERER" "https://www.googleapis.com/youtube/v3/channels?part=snippet,contentDetails,statistics,status&maxResults=50&forUsername=YOUR_USERNAME&key=YOUR_KEY"
# Find "Uploads" playlist ID at items => contentDetails => relatedPlaylists => uploads.
# Find Channel ID at items => id.
#
@bdunagan
bdunagan / how-to-disable-multi-touch-on-apple-magic-mouse.bash
Created Dec 5, 2016
Terminal: How to Disable Multi-Touch on Apple Magic Mouse
View how-to-disable-multi-touch-on-apple-magic-mouse.bash
# Launch Terminal.
defaults write com.apple.AppleMultitouchMouse MouseMomentumScroll -bool NO
defaults write com.apple.AppleMultitouchMouse MouseHorizontalScroll -bool NO
defaults write com.apple.AppleMultitouchMouse MouseVerticalScroll -bool NO
defaults write com.apple.driver.AppleBluetoothMultitouchMouse MouseMomentumScroll -bool NO
defaults write com.apple.driver.AppleBluetoothMultitouchMouse MouseHorizontalScroll -bool NO
defaults write com.apple.driver.AppleBluetoothMultitouchMouse MouseVerticalScroll -bool NO
# Restart the computer.
@bdunagan
bdunagan / salesforce-territories.txt
Created Dec 25, 2016
Salesforce: How to Set Up Sales Territories with a Read-Only Custom Formula
View salesforce-territories.txt
# Salesforce Custom Formula for Worldwide Sales Territories
IF(ISBLANK(Country),"North America",
IF(CONTAINS("US:CA:PR",Country),"North America",
IF(CONTAINS("DE:AT:CH",Country),"DACH",
IF(CONTAINS("FR:MC:NC:PF:GP:RE:MQ:GY",Country),"France",
IF(CONTAINS("ES",Country),"Spain",
IF(CONTAINS("PT",Country),"Portugal",
IF(CONTAINS("IT",Country),"Italy",
IF(CONTAINS("AG:AI:AN:AR:AW:BB:BM:BO:BR:BS:BZ:CL:CO:CR:CU:DM:DO:EC:FK:GD:GL:GT:GY:HN:HT:JM:KN:KY:LC:MS:MX:NI:PA:PE:PM:PY:SR:SV:TC:TT:UY:VC:VE:VG:VI",Country),"Latam",
IF(CONTAINS("AS:AU:CK:CN:CX:FJ:FM:GU:HK:ID:JP:KH:KI:KP:KR:LA:MH:MM:MN:MO:MP:MY:NF:NR:NU:NZ:PG:PH:PN:PW:SB:SG:TH:TK:TO:TV:TW:VN:VU:WF:WS",Country),"APAC",