Skip to content

Instantly share code, notes, and snippets.

View dtuite's full-sized avatar
🚀
Shipping

David Tuite dtuite

🚀
Shipping
View GitHub Profile
@dtuite
dtuite / sudo-pipe.md
Created March 3, 2014 02:25
Pipe to a file with sudo permissions

Pipe to a file using sudo

The tee -a command will append changes to a file (just like to >>). The -a flag stands for "append".

echo "some text" | sudo tee -a write-protected.txt

@dtuite
dtuite / non-ascii.sh
Created February 27, 2014 15:26
Find non-ASCII characters. This is useful when (for example) you have a Rails application and you want to specify UTF-8 encoding magic comment on files which need it. This snippet will tell you which files.
find . -type f -exec file --mime {} \; | grep -v us-asci
@dtuite
dtuite / share_bar.erb
Created February 11, 2014 12:53
Code sample for displaying sharing bar when certain percentage scrolled
<div class="share-bar">
<%= @post.tweet_button -%>
<%= @post.share_button -%>
<%# No point showing this on mobiles since they can't easily copy/paste
the URL into an RSS app. %>
<%= @post.rss_button unless mobile_device? -%>
</div>
@dtuite
dtuite / 0.md
Last active December 28, 2015 08:39
Backup and Restore a PostgreSQL Database

PostgreSQL Backup and Restore

@dtuite
dtuite / qnorm.js
Last active April 15, 2020 04:35
qnorm.js
// Originally found at: http://rangevoting.org/Qnorm.html
/** * @(#)qnorm.js * * Copyright (c) 2000 by Sundar Dorai-Raj
* * @author Sundar Dorai-Raj
* * Email: [email protected]
* * This program is free software; you can redistribute it and/or
* * modify it under the terms of the GNU General Public License
* * as published by the Free Software Foundation; either version 2
* * of the License, or (at your option) any later version,
* * provided that any use properly credits the author.
@dtuite
dtuite / mobile_detector.rb
Created September 17, 2013 08:48
Mobile device detection class.
# Discussion: http://stackoverflow.com/q/1005153/574190
# Railscast: http://railscasts.com/episodes/199-mobile-devices
# More Infor: http://detectmobilebrowsers.com/
# Hacky because of Regex but that seems to be the way that this is done around
# the net. THere are some gems out there which will provide similar
# functionality.
#
# Check out:
#
@dtuite
dtuite / remove_trailing_whitespace.sh
Last active October 12, 2023 16:46
Recursively remove trailing whitepace from files.
# Remove trailing whitespace from files in the src directory.
# This is useful because (for example) trailing whitespace hinders Vim's
# paragraph movement.
# INFO: http://stackoverflow.com/a/4438318/574190
# INFO: http://stackoverflow.com/q/1583219/574190
# The directory under which we want to search for files.
ROOT_DIRECTORY="$1"
@dtuite
dtuite / sed.sh
Created July 17, 2013 10:43
Using Sed on OSX
sed -i '' 's/TextToChange/ChangeToThis/g' spec/features/*.rb
# -i '' forces the files to be edited in place
@dtuite
dtuite / find_sed.sh
Last active December 19, 2015 21:19
Example of using sed to find and replace recursively in a hierarchy of directories.
# http://stackoverflow.com/a/1583282/574190
find app/views -type f -print0 -name "*.erb" | xargs -0 sed -i '' 's/Et\.trac/mixpanel\.trac/g'
# Not sure why the following isn't equivilent.
sed =i '' 's/Et\.trac/mixpanel\.trac/g' app/views/**/*.html.erb
@dtuite
dtuite / local_mysql.md
Last active December 16, 2015 16:49
Basic Local mysql

Starting/Stopping server

It doesn't start automatically at login

mysql.server start
mysql.server stop

Login as root user

mysql -uroot -p