Skip to content

Instantly share code, notes, and snippets.

@tjmcewan
tjmcewan / unsyncer.js
Last active December 15, 2015 02:29
Sync or Unsync all Box folders on the current page
$('#mod-item-list>li').each(function(index, el){
// defaults to unsync; to sync, set unsync to 0
var unsync = 1;
var folder_id = el.attributes['data-view_id'].textContent;
var data = ["q[items][0]=", folder_id, "&q[unsync]=", unsync, "&request_token=", request_token, "&realtime_subscriber_id=", realtime_subscriber_id].join('');
var url = ["https://", location.host, "/index.php?rm=box_sync_mark_item_sync"].join('');
$.post(url, data, function(x,status,z){ console.log(folder_id, ': ', status) });
});
@tjmcewan
tjmcewan / git-rebase-todo
Last active December 19, 2015 06:59
multi-stage deploy using git rebase -i
# x (or exec) will run anything on the same line as a shell command.
# we need to checkout a temporary branch because git won't push detached HEADs.
# after deploy, the "checkout -" means checkout the previously checked out thing,
# which will go back to our detached head and we clean up the temporary branch so
# that we don't need to worry about merging.
# if your branch is already based on the same point as your rebase command, then
# the 'pick' stage is essentially the same as a fast-forward merge; no new commits
# are created.
@tjmcewan
tjmcewan / branch_handling.md
Last active October 31, 2017 19:15
some options & shortcuts to make git branch management simple and sane

Run these once to setup git options:

git config --global push.default current
git config --global merge.defaultToUpstream true
git config --global branch.autosetupmerge true
git config --global branch.autosetuprebase remote
git config --global alias.cb 'checkout -b'
git config --global alias.ps 'push -u'
git config --global alias.pl '!git fetch -p && git rebase'

Use them like this:

@tjmcewan
tjmcewan / database.yml
Last active December 24, 2015 13:29
app-agnostic, feature branch supporting, drop-in database.yml(based on http://www.reinteractive.net/posts/22-branch-specific-database-yml)
<%
app_name = Dir.getwd.split('/')[-1]
branch = `git symbolic-ref --short HEAD 2>/dev/null`.chomp.gsub(/\W/, '_')
db_name = branch.match(/feature/) ? "#{app_name}_#{branch}" : "#{app_name}_master"
puts "DATABASE: #{db_name}"
%>
mysql2: &mysql2
adapter: mysql2
socket: /tmp/mysql.sock
@tjmcewan
tjmcewan / instructions.md
Last active December 26, 2015 11:59
Ninefold db updates

This is a quick way to Push or Pull your app database between your local machine and your Ninefold app server. "Pushing" is useful in the early stages of app development when you need to update seed data. "Pulling" is eternally useful for debugging.

  1. setup public key authentication (the SSH username is "user"). NB ensure you don't remove the existing SSH key - it's needed by the Ninefold Portal.

  2. obtain your database password from the "database" tab in the Ninefold portal.

  3. put the password where Postgres can find it (on the database server): echo "localhost:*:*:app:<PASSWORD>" > ~/.pgpass then chmod 0600 .pgpass more info on password files

@tjmcewan
tjmcewan / inside.sh
Created November 26, 2013 13:11
inside the heroku beast
~/projects$ h run bash
Running `bash` attached to terminal... up, run.2192
~ $ uname -a
Linux 7fa29fb1-2e9c-4510-a0a7-df92cfaff4c8 3.8.11-ec2 #1 SMP Fri May 3 09:11:15 UTC 2013 x86_64 GNU/Linux
~ $ free -m
total used free shared buffers cached
Mem: 34302 29994 4307 0 1927 8232
-/+ buffers/cache: 19835 14466
Swap: 34815 732 34083
@tjmcewan
tjmcewan / email.md
Last active August 29, 2015 13:57
email for Rails Girls organisers to forward to their networks

Hi there,

If you're interested in taking your web journey to the next level and would love to contribute to the open source community, consider applying for a paid scholarship for this year's Rails Girls Summer of Code.

It will run from July to September 2014, and will see you contribute to an open source project of your choice. You'll be increasing your coding skills, with help from a coach or two, and will be making a significant contribution to the community.

Applications close May 2nd, but there's a fair bit to do before then, so don't delay. :) Read more on what's required in the application guide.

If you're curious and want to know more first, you can check out the FAQ.

@tjmcewan
tjmcewan / snakify.rb
Last active August 29, 2015 13:57 — forked from puyo/encamel.rb
#!/usr/bin/env ruby
gem 'activesupport'
require 'active_support/core_ext/string/inflections'
camel = ARGV.first
snake = camel.underscore
system %{git grep -l #{camel} | xargs ruby -p -i -e '$_.gsub! /#{camel}/, "#{snake}"'}
@tjmcewan
tjmcewan / jquerify.js
Created April 2, 2014 00:25
protocol independent jquerify
javascript:(function()%7Bvar el%3Ddocument.createElement("div"),b%3Ddocument.getElementsByTagName("body")%5B0%5D,otherlib%3D!1,msg%3D""%3Bel.style.position%3D"fixed",el.style.height%3D"32px",el.style.width%3D"220px",el.style.marginLeft%3D"-110px",el.style.top%3D"0",el.style.left%3D"50%25",el.style.padding%3D"5px 10px",el.style.zIndex%3D1001,el.style.fontSize%3D"12px",el.style.color%3D"%23222",el.style.backgroundColor%3D"%23f99"%3Bfunction showMsg()%7Bvar txt%3Ddocument.createTextNode(msg)%3Bel.appendChild(txt),b.appendChild(el),window.setTimeout(function()%7Btxt%3Dnull,typeof jQuery%3D%3D"undefined"%3Fb.removeChild(el):(jQuery(el).fadeOut("slow",function()%7BjQuery(this).remove()%7D),otherlib%26%26(window.%24jq%3DjQuery.noConflict()))%7D,2500)%7Dif(typeof jQuery!%3D"undefined")return msg%3D"This page already using jQuery v"%2BjQuery.fn.jquery,showMsg()%3Btypeof %24%3D%3D"function"%26%26(otherlib%3D!0)%3Bfunction getScript(url,success)%7Bvar script%3Ddocument.createElement("script")%3Bscript.src%3Durl%3Bvar he
exclude_patterns() {
exclude="-false" # need to start the list somewhere so we have the right number of "-or"
for exclude_folder in .git .bundle tmp log; do
exclude="$exclude -or -name $exclude_folder -prune"
done
for exclude_file in Gemfile.lock structure.sql '*.gif' '*.jpg' '*.png' '*jquery*' '*.doc' '*.pdf' '*.zip' '*.ico' '*.swf' '*.sqlite' '*.ttf'; do
exclude="$exclude -or -iname $exclude_file"
done