Skip to content

Instantly share code, notes, and snippets.

@bjdixon
bjdixon / change_git_remote_url.sh
Created October 4, 2016 10:09
Change git remote url
git remote -v
git remote set-url origin new_url_to_repo.git
@bjdixon
bjdixon / remove_docker_images.sh
Last active August 5, 2016 11:51
Remove all exited docker images
sudo docker ps -a | grep Exited | cut -d ' ' -f 1 | xargs sudo docker rm
@bjdixon
bjdixon / sedReplace.sh
Created May 20, 2016 10:13
Use sed to replace contents in a file
sed -i 's/replacementString/stringToReplace/g' /path/to/filename
@bjdixon
bjdixon / fetch.js
Created May 10, 2016 13:57
Example of using fetch to get json data
fetch(url)
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.log(err))
@bjdixon
bjdixon / grep_through_git_diff.sh
Created March 7, 2016 18:37
grep through contents of the list of files returned by git diff
git diff --name-only master | xargs cat | grep "keyword"
@bjdixon
bjdixon / kill.sh
Created November 24, 2015 16:08
kill processes matching a search pattern
kill $(ps aux | grep SEARCH_PATTERN | awk '{print $2}')
@bjdixon
bjdixon / last_curl.sh
Created November 2, 2015 17:30
run last curl command
eval $(cat ~/.bash_history | grep curl | head -1 | awk '{print}')
@bjdixon
bjdixon / findKey.js
Created October 13, 2015 15:47
returns first key that passes predicate
function findKey(obj, predicate) {
for (var prop in obj) {
if(obj.hasOwnProperty( prop ) ) {
if (predicate(obj[prop])) {
return prop;
}
}
}
}
@bjdixon
bjdixon / getParams.js
Created October 2, 2015 00:50
Get querystring key value pairs
// get the querystring key value pairs
// eg. http:www.example.com/document?a=1&b="2"&c=JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B
// will return {a: "1", b: "2", c: "JavaScript_шеллы"}
var params = (function getURLParams(qs) {
var pairs = {};
qs.forEach(function(param) {
var pair = param.split('=');
pairs[pair[0]] = decodeURIComponent(pair[1].replace(/\"/g, ''));
});
@bjdixon
bjdixon / maybe.js
Created September 10, 2015 18:15
takes a function and returns a function that will only be applied if it has arguments that aren't null or undefined
function maybe(fn) {
return function () {
var args = Array.prototype.slice.call(arguments);
if (!args.length) {
return;
}
for (var index = 0, length = args.length; index < length; index += 1) {
if (args[index] == null) {
return;
}