Skip to content

Instantly share code, notes, and snippets.

@bdunagan
bdunagan / salesforce-opportunity-field-days-since-release.txt
Last active March 18, 2017 13:11
Salesforce: Add an Opportunity formula field for "Days since release"
# Salesforce Custom Formula for "Days Since Release" based on Opportunity CloseDate
IF(
/* 2012 - Win 8, Mac 10 */
AND(
CloseDate >= DATE(2012,11,6),
CloseDate < DATE(2014,3,4)
),
CloseDate - DATE(2012,11,6),
IF(
/* 2014 - Win 9, Mac 11 */
@bdunagan
bdunagan / salesforce-opportunity-field-release-name.txt
Last active March 18, 2017 13:11
Salesforce: Add an Opportunity formula field for "Release Name"
# Salesforce Custom Formula for Release Name based on Opportunity CloseDate
IF(
/* 2012 - Win 8, Mac 10 */
AND(
CloseDate >= DATE(2012,11,6),
CloseDate < DATE(2014,3,4)
),
"2012 - Win 8, Mac 10",
IF(
/* 2014 - Win 9, Mac 11 */
@bdunagan
bdunagan / salesforce-report-object.rb
Created January 29, 2017 10:44
Salesforce: Create a Report object using Analytics API
# Instantiate Salesforce Report using Restforce.
# Requires Salesforce Analytics API with v29.
# Usage
# report = Restforce::Report.find("1234567890")
# puts report.name
# puts report.filters
# puts report.rows
module Restforce
@bdunagan
bdunagan / salesforce-timezones.txt
Created December 29, 2016 04:34
Salesforce: How to Set Up US Timezones with a Custom Formula
# Salesforce Custom Formula for US Timezones based on Billing State
# Note there are 51 because DC counts.
CASE(BillingState,
"HI","US-PST",
"AK","US-PST",
"WA","US-PST",
"OR","US-PST",
"CA","US-PST",
"NV","US-PST",
"MT","US-MST",
@bdunagan
bdunagan / salesforce-territories.txt
Created December 25, 2016 17:13
Salesforce: How to Set Up Sales Territories with a Read-Only Custom Formula
# 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",
@bdunagan
bdunagan / how-to-disable-multi-touch-on-apple-magic-mouse.bash
Created December 5, 2016 21:08
Terminal: How to Disable Multi-Touch on Apple Magic Mouse
# 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.
# 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.
#
# 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| %>
# 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
# 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