Skip to content

Instantly share code, notes, and snippets.

View tpinto's full-sized avatar

Tiago Pinto tpinto

View GitHub Profile
@tpinto
tpinto / awesome_nested_set.rb
Created March 10, 2011 19:13
awesome nested set, .rebuild! method fully commented (WIP)
# Rebuilds the left & rights if unset or invalid. Also very useful for converting from acts_as_tree.
def rebuild!
# Don't rebuild a valid tree.
return true if valid?
# defines the method _scope_ to return _nil_
scope = lambda{|node|}
# if the _:scope_ option was set, we must use it
if acts_as_nested_set_options[:scope]
@tpinto
tpinto / bootstrap-v2.sh
Last active September 9, 2016 10:46 — forked from erikh/hack.sh
OSX Customized
echo "Inverting scroll direction"
defaults write ~/Library/Preferences/.GlobalPreferences com.apple.swipescrolldirection -bool false
echo "Enable the 2D Dock"
defaults write com.apple.dock no-glass -bool true
echo "Automatically hide and show the Dock"
defaults write com.apple.dock autohide -bool true
echo "Make Dock icons of hidden applications translucent"
@tpinto
tpinto / hash_deeper_merge.rb
Last active August 29, 2015 13:55
Just like Hash#deep_merge but works with Arrays, applying the default to each element inside it.
class Hash
def deeper_merge(overriding_hash)
ret = self.merge(overriding_hash) do |key, default_val, overriding_val|
if default_val.class == Array and overriding_val.class == Array
resulting_array = []
for little_hash in overriding_val
resulting_array << default_val.first.deeper_merge(little_hash)
end
resulting_array
else
@tpinto
tpinto / xcode-auto-version.sh
Last active March 28, 2022 11:22
Xcode: Automatic version and build number for iOS apps on Info.plist and Settings.bundle - http://www.tiagopinto.pt/blog/2014/11/10/xcode-version-build-number-ios-info-plist-settings-bundle/
# Tips from: http://xcodehelp.blogspot.ie/2012/05/add-version-number-to-settings-screen.html
# Reference from: https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html
# Get the correct path for the git binary
git=`sh /etc/profile; which git`
# Save paths for the project and target Info.plist
projectPlistPath="${PROJECT_DIR}/${INFOPLIST_FILE}"
targetPlistPath="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

-- forgot to save the first one. sorry about that
SELECT t.name, t.composer
FROM tracks t
JOIN playlist_tracks pt ON pt.track_id = t.id
JOIN playlists p ON pt.playlist_id = p.id
WHERE p.name = 'Classical'
LIMIT 10;
SELECT a.name, COUNT(*) AS count