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 / taps_linode.md
Created March 24, 2013 19:58
Pulling data from Linode with Taps

Start server on Linode

taps server postgres://[DB_USER]:[DB_PASSWORD]@localhost/[DB_NAME] [USER_NAME] [USER_PASSWORD]

where:

  • DB_USER is the name of the user for the database we want to pull from.
  • DB_PASSWORD is the password of that user.
@dtuite
dtuite / ascii_finder.sh
Created April 11, 2013 15:35
Find ASCII chars in a directory. Useful for when you're getting encoding errors and you're not sure exactly where they're coming from.
cat lib/tasks/* | perl -n -e 'print if /[^\x00-\x7F]/'
@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

@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 / 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 / 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 / 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 / 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 / 0.md
Last active December 28, 2015 08:39
Backup and Restore a PostgreSQL Database

PostgreSQL Backup and Restore

@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>