Skip to content

Instantly share code, notes, and snippets.

View onpaws's full-sized avatar
🚴‍♂️
building things

Pat onpaws

🚴‍♂️
building things
View GitHub Profile
@onpaws
onpaws / bash-template.sh
Created April 16, 2014 20:04
bash: start here
#!/bin/bash
set -o nounset
set -o errexit
<<COMMENT
via http://robertmuth.blogspot.com/2012/08/better-bash-scripting-in-15-minutes.html
To perform a syntax check/dry run of your bash script run:
bash -n myscript.sh
@whistler
whistler / run_tests.sh
Created June 6, 2012 13:47
Pull Rails application and test repeatedly
#!/bin/bash
while [ true ]; do
git pull origin master
bundle install
rake db:migrate
rake rake:test:prepare
rake spec
done
@whistler
whistler / no_timestamps_in_json.rb
Created June 11, 2012 15:10
Dont send timestamps of Rails records to browser
class ActiveRecord::Base
def as_json(options={})
super(:except => [:created_at, :updated_at])
end
end
@sweir27
sweir27 / gist:4ea941dd717da69527d6
Last active October 13, 2015 06:48
React drag/drop
dragStart: function(e) {
this.setState({dragMouseStart: e.clientY, draggingElementId: e.currentTarget.getAttribute('data-slug')})
e.dataTransfer.effectAllowed = 'move';
},
dragOver: function(e) {
e.preventDefault();
var over = e.currentTarget; // element we're hovering over
var draggingId = this.state.draggingElementId;
var toElId = over.getAttribute('data-slug');
@onpaws
onpaws / gist:5085327
Last active December 14, 2015 12:19
MySQL snippets 2.weeks.ago in MySQL, view consumed and available space
select DATE_SUB(curdate(), INTERVAL 2 WEEK)
-- Space consumed by databases
SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema;
-- Free space available
SELECT table_schema "Database Name", sum( data_length + index_length ) / 1024 / 1024 "Database Size in MB", sum( data_free )/ 1024 / 1024 "Free Space in MB" FROM information_schema.TABLES GROUP BY table_schema;
@awesome
awesome / ffaker-example-output.md
Last active September 22, 2016 21:08
got ffaker gem documentation? me neither, but here's a list of the class methods… so awesome 😂!
@johnbintz
johnbintz / Guardfile
Created January 31, 2013 16:38
Make guard, guard-livereload, and a Rails server play nice in Foreman, so that you can see logs in the Foreman output and so Guard doesn't take over the input/output.
group :livereload do
guard 'livereload' do
watch(things)
end
end
@joho
joho / deploy.rb
Created September 13, 2012 01:30
How to serve emergency "signed out" views from page cache without affecting signed in users in rails.
set :path_to_repo, "/path_to_repo/"
set :running_app_user, "appusername"
namespace :webscale do
desc "Cache a signed out version of the path. Usage: cap webscale:signed_out_cache_page -s path_to_cache=/films/on_netflix"
task :signed_out_cache, roles: :app do
cache_base_path = "#{path_to_repo}/public/signed_out"
cached_destination_path = "#{cache_base_path}#{path_to_cache}.html"
working_path = "#{cached_destination_path}.tmp"
@brentsimmons
brentsimmons / gist:5810992
Last active January 3, 2021 02:22
Detect a tap on a URL inside a UITextView. Note: the rs_links method isn't included -- you'll need something that takes text and returns an array of detected links. This gist just demonstrates walking through the UITextView characters.
@implementation UITextView (RSExtras)
static BOOL stringCharacterIsAllowedAsPartOfLink(NSString *s) {
/*[s length] is assumed to be 0 or 1. s may be nil.
Totally not a strict check.*/
if (s == nil || [s length] < 1)
return NO;
@chengyin
chengyin / linkedout.js
Last active July 11, 2021 15:23
Unsubscribe all LinkedIn email in "one click". For an easier to use version, you can check out the bookmarklet: http://chengyin.github.io/linkedin-unsubscribed/
// 1. Go to page https://www.linkedin.com/settings/email-frequency
// 2. You may need to login
// 3. Open JS console
// ([How to?](http://webmasters.stackexchange.com/questions/8525/how-to-open-the-javascript-console-in-different-browsers))
// 4. Copy the following code in and execute
// 5. No more emails
//
// Bookmarklet version:
// http://chengyin.github.io/linkedin-unsubscribed/