Skip to content

Instantly share code, notes, and snippets.

@jwliechty
jwliechty / adjust_markdown.rb
Last active September 3, 2015 12:59
This script will modify a markdown file in order to trim paragraph and list items to 80 characters.
def usage
"#{$0} FILE"
end
file = ARGV.first
$stderr.puts usage unless (file && File.file?(file))
class MarkdownTruncate
@jwliechty
jwliechty / touch_parents_on_modify.rb
Created March 18, 2015 18:25
Update parent timestamps when embedded mongoid docs modified
module TouchParentsOnModify
def update(attributes={})
touch_parents
super attributes
end
def save(options={})
touch_parents
super options
end
@jwliechty
jwliechty / rpm_build_commands.sh
Created November 18, 2014 17:26
Building RPMs
# install tools for working with RPMs
sudo yum groupinstall "Development Tools"
sudo yum install rpmlint rpmdevtools yum-utils
# add a Centos source repository
cat <<EOF | sudo tee /etc/yum.repos.d/srpm.repo >/dev/null
[centos-source]
name=Centos Vault $releasever - $basearch - Source
baseurl=http://vault.centos.org/6.3/os/Source
enabled=1
@jwliechty
jwliechty / createPatchTarBetween.sh
Last active January 31, 2017 16:20
This script helps in creating a tar.gz file containing only modified and added files from between two commits in a git repository. The idea is for deployed applications, to update only the changed files for a hotfix or small update, this tar can be created and extracted over that existing directory. Of course this only works if there were additi…
#/bin/bash -e
START_BRANCH="$1"
END_BRANCH="$2"
PATCH_TAR=patch.tar.gz
COMMIT_HASH_FILE=commit_hash
usage(){
echo ""
echo "USAGE: $0 START END"
@jwliechty
jwliechty / find_ids_of_demension_mult_attributes.sql
Created September 15, 2014 19:15
Find id's of a dimension referenced from a fact table via multiple attributes.
SELECT dim.id FROM dim WHERE dim.id NOT IN
(
SELECT DISTINCT fact.dim_one_id FROM fact
)
AND dim.id NOT IN
(
SELECT DISTINCT fact.dim_two_id FROM fact
)
AND dim.id NOT IN
(
@jwliechty
jwliechty / delete_unused_foreign_keys.sql
Last active August 29, 2015 14:06
Delete all unused foreign keys in 'child' that are supposed to be referenced from 'parent'. (Rows in child belong to rows in parent where child.id = parent.child_id).
DELETE FROM child WHERE id IN
(
SELECT child.id FROM child LEFT JOIN parent ON child.id=parent.child_id WHERE parent.child_id IS NULL
);
@jwliechty
jwliechty / gist:0fe68a416d338c373c82
Last active August 29, 2015 14:04
Update RubyMine on Ubuntu
cd /usr/local/lib/ruby/
sudo mv ~/Downloads/RubyMine-7.1.1.tar.gz .
tar xzf RubyMine-7.1.1.tar.gz
sudo chown -R jwliechty:jwliechty RubyMine-7.1.1
update-alternatives --list rubymine
sudo update-alternatives --install /usr/bin/mine rubymine /usr/local/lib/ruby/RubyMine-7.1.1/bin/rubymine.sh 1
sudo update-alternatives --config rubymine
vi /home/jwliechty/.gnome2/panel2.d/default/launchers/mine-1.desktop
@jwliechty
jwliechty / gist:9936616
Created April 2, 2014 15:37
run_until_fails.sh
runUntilFails(){
local cmd="${1:?"Must give a command as a string"}"
local count=0
echo "Running cmd: ${cmd}"
while eval "${cmd} ; return $?"; do
((count+=1))
echo "Try count: ${count}"
done
}
@jwliechty
jwliechty / gist:8920847
Last active August 29, 2015 13:56
Stuff with ports
# see what process is using a port
sudo netstat -anp
# scan the ports
sudo nmap -sS -O 127.0.0.1
@jwliechty
jwliechty / script_directory.sh
Last active December 25, 2015 14:39
bash: Determine script directory
SCRIPT_DIR="$(readlink -f $(dirname $0))"
#or if must be supported on MAC
SCRIPT_DIR="$(cd "$(dirname "$0")"; pwd)"