Skip to content

Instantly share code, notes, and snippets.

@spudfkc
spudfkc / findString.sh
Last active December 20, 2015 10:30
Looks for occurrences of a string in all files in the specified directory (defaults to current) For best results put in ~/.bashrc
findString() {
if [ -z "$1" ]
then
echo "usage: findString "string" [whereToLook]"
return 1
fi
if [ -z "$2" ]
then
wheretolook=$(pwd)
@spudfkc
spudfkc / killProcs.sh
Last active December 20, 2015 10:30
Kills all processes found with the given keyword
#!/bin/bash
echo $1
ps aux | grep $1 | grep -v grep | awk '{print $2}' | xargs kill -9
@spudfkc
spudfkc / clearTmpFiles.sh
Created August 6, 2013 19:22
clears any files ending in ~ (gedit) or .orig (meld)
#!/bin/bash
if [ -z "$1"]
then
WORKSPACE=$(dirname $0)/..
else
WORKSPACE=$1
fi
find $WORKSPACE -type f -name "*.orig" -print | xargs -0 rm -f
@spudfkc
spudfkc / bdr.sh
Last active December 20, 2015 17:19
Starts server, optionally re-deploys static content and war, assuming jslint passes
#!/bin/bash
DEPLOY_DIR=/opt/udeploy/server
PWD=$(dirname $0)
if [ -n "$1" ] ; then
# run jslint
git --git-dir $PWD/../.git --work-tree $PWD/.. jslint
LINT_EXIT=$?
# only keep going if exit 0
if [ "$LINT_EXIT" -ne "0" ]
@spudfkc
spudfkc / deployStatic.sh
Last active December 20, 2015 17:19
Deploys static server content
#!/bin/bash
DEPLOY_DIR=/opt/udeploy/server
VERSION=dev
DIR=$(dirname $0)
if [ -z "$1" ]
then
git jslint --git-dir $DIR/.. --work-tree $DIR/..
fi
@spudfkc
spudfkc / git-jslint
Created August 6, 2013 19:28
git command for running jslint on diff'd files
#!/bin/bash
git rev-parse || exit 1
#jslint properly handles no files being specified
DIFFBASE=HEAD
FILES=$( git diff --diff-filter=AMCR --name-only --relative "$DIFFBASE" -- "$@" )
if [ -z "$FILES" ]
then
echo "no files to scan"
@spudfkc
spudfkc / git-submit
Created August 6, 2013 19:29
submit to gerrit server - credit goes to @jwadamson you will need to set the 'submit.remote' attribute for git (e.g. `git config --global submit.remote review`)
#!/bin/bash
remote=$(git config --get submit.remote )
current=$( git rev-parse --symbolic-full-name --abbrev-ref HEAD )
upstream=$(git rev-parse --symbolic-full-name --abbrev-ref @{u} )
upstream=${upstream#*/} # trim the leading remote name portion
if [ -z "$remote" ]
then
echo "submit.remote is not set"
@spudfkc
spudfkc / git-gclone
Created September 24, 2013 22:05
Clones a repo and sets it up for Gerrit server. Only tested in bash. not super portable, but i find it useful I would recommend putting it in /usr/lib/git-core/
#!/bin/bash
if [ -z $1 ]
then
echo "Must supply a git project."
echo "Usage git gclone <project-url>"
return 1
fi
ORIGIN=$1
@spudfkc
spudfkc / shibe-scraper.py
Last active December 24, 2015 12:38
wow very scriptsuch code so python wow lolshibeGrabs the images from the front page of /r/supershibe and writes them to "links.html"Requires BeautifulSoup4
import urllib2
from bs4 import BeautifulSoup as bs
def scrape_site(url):
result = []
soup = bs(urllib2.urlopen(url).read())
for img in soup.find_all('img'):
if img.has_attr('alt'):
src = img.get('src')
@spudfkc
spudfkc / unallowed-branches.sh
Created October 31, 2013 19:37
prevents committing to certain git branches. I made this because I would accidentally commit to master instead of a feature branch. This could cause a mess with dependencies and gerrit. Not committing to master was the easiest solution for that. How To Use: put this in <repo>/.git/hooks/pre-commit
#!/bin/bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
array_contains() {