Skip to content

Instantly share code, notes, and snippets.

View jamie-ga's full-sized avatar

Jamie Weatherby jamie-ga

View GitHub Profile
// App.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import WishlistApp from './wishlist/App';
import VisaCheckerApp from './visa-checker/App'
import TripSearchApp from './trip-search/App'
import { store } from './store'
const WishlistDOM = document.getElementById('wishlist-app')
@jamie-ga
jamie-ga / profile-slow-queries-postgres
Created June 20, 2018 19:35
Measuring / profiling postgres queries
SELECT query, calls, total_time, rows,
100.0 * shared_blks_hit / nullif(shared_blks_hit + shared_blks_read, 0) AS hit_percent
FROM pg_stat_statements ORDER BY total_time DESC LIMIT 100;
@jamie-ga
jamie-ga / rename-changed-files.sed
Created August 11, 2016 14:01
sed rename a load of files
for f in `git diff master --name-only`; do cp $f `echo $f | sed -E 's/\.(scss|html)/-v2.\1/'` ; done
@jamie-ga
jamie-ga / postactivate.sh
Last active February 27, 2016 21:49
Setting a custom ps1 variable
#!/bin/bash
# This hook is sourced after every virtualenv is activated.
# Added to $WORKON_HOME/.virtualenvs/postactivate
# color virtualenv name properly and put it after the \n if there is one at the start of the prompt
if [ ${_OLD_VIRTUAL_PS1:0:2} == '\n' ]; then
PS1="\n\[\033[$PROMPT_COLOR1\](`basename \"$VIRTUAL_ENV\"`) ${_OLD_VIRTUAL_PS1:2:${#_OLD_VIRTUAL_PS1}}"
else
PS1="\[\033[$PROMPT_COLOR1\](`basename \"$VIRTUAL_ENV\"`) $_OLD_VIRTUAL_PS1 "
@jamie-ga
jamie-ga / mygrep.sh
Created November 10, 2015 15:32
Customized grep of specific filetypes (defaults to python)
#!/bin/bash
flags=""
extension="py"
search_term=""
verbose=""
help_str="\n\tmygrep [-f|--flags flags] [-v|--verbose] [-x|--ext extension]\n"
if [ $# -eq 0 ]; then
# .tmux.conf
# set leader to capslock (need to disable capslock functionality first)
set-option -g prefix F10
# allow double click on session to switch
set -g mouse-select-pane on
# allow vi like functionality (key for copy pasting)
set -g mode-keys vi
@jamie-ga
jamie-ga / rm_pip_commits.vim
Last active August 29, 2015 14:26
In pip freeze > requirements.txt, the specific commit used is included. This one-liner removes that and preserves the useful info.
%s/@[^@#]*#egg/#egg/g
@jamie-ga
jamie-ga / all_pdb_variables.py
Created July 21, 2015 17:28
Printing all the local variables in pdb.set_trace()
{k: v for k,v in locals().iteritems() if '__' not in k and 'pdb' not in k}
@jamie-ga
jamie-ga / tmux.conf
Last active June 30, 2016 23:12
Personal Vim Config for python development (still in progress)
# 0 is too far from ` ;)
set-option -g prefix F10
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
@jamie-ga
jamie-ga / bash-examples.sh
Last active August 29, 2015 14:24
Migrations one-line scripts
# Do a load of inline edits using grep instead of perl
for d in $(grep -rl "from conf.cache_times" *); do sed -i '' 's/from conf.cache_times/from sites.conf.cache_times/g' $d; done
# Rename a load of directories from the command line
for d in $(find . -name 'migrations' -type d); do mv $d $(echo $d | sed 's/migrations/south_migrations/' | sed 's/\.\///g'); done
# Running a series of makemigrations on the apps found that do not already have migrations
for d in $(find . -type d -maxdepth 1); do if [ ! -d "$d/migrations" ]; then python manage.py makemigrations $(echo $d | sed 's/\.\///'); fi; done
# using awk - get stuff between double quotes