Skip to content

Instantly share code, notes, and snippets.

View RyanFrench's full-sized avatar

Ryan French RyanFrench

View GitHub Profile
@RyanFrench
RyanFrench / utils.clj
Created October 17, 2017 07:45
Associate optional fields in a map
(defn assoc-optionals
"Associate optional fields in a map if they are not nil"
([map key val]
(merge
map
(when-not (nil? val) {key val})))
([map key val & kvs]
(let [ret (assoc-optionals map key val)]
(if kvs
(if (next kvs)
@RyanFrench
RyanFrench / docker_cleanup.sh
Last active April 1, 2016 08:35
Docker Cleanup
# Kill all running containers
docker kill $(docker ps -q)
# Remove all containers
docker rm $(docker ps -a -q)
# Remove all dangling images
docker rmi $(docker images -q --filter "dangling=true")
# Remove all images
@RyanFrench
RyanFrench / update_pip.sh
Created April 1, 2016 07:17
python pip update all packages
#!/bin/bash
pip list --outdated | awk '{print $1}' | xargs -n1 pip install -U
@RyanFrench
RyanFrench / .bash_profile
Last active November 17, 2015 12:11
Custom Bash Prompt
# Credit to http://martinfitzpatrick.name/article/add-git-branch-name-to-terminal-prompt-mac/
# Get the current branch of the repo
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# Trim the working directory
PROMPT_DIRTRIM=2
Style/FileName:
Exclude: ['Vagrantfile', 'Gemfile', 'Berksfile', 'Dockerfile']
@RyanFrench
RyanFrench / sortedGroupBy.js
Last active October 19, 2016 09:53
Group array by property and sort by property. Requires Underscore.js or lodash.js
_.mixin({
sortedGroupBy : function(list, groupByIter, sortByIter) {
var groupBy = groupByIter;
if (_.isArray(groupByIter)) {
function groupBy(obj) {
return _.map(groupByIter, function(key, value) {
return obj[key];
});
}
}
@RyanFrench
RyanFrench / exportCSV.js
Last active December 21, 2015 10:09
Turn array into a CSV URI for exporting. Requires Underscore.js or LoDash.js
_.mixin({
exportCSV : function(array, exportColumns, includeHeaders) {
includeHeaders = typeof includeHeaders !== 'undefined' ? includeHeaders : true;
var csvData = [];
if(array.length > 0 && exportColumns.length > 0) {
if(includeHeaders) csvData = [_.chain(array[0]).pick(exportColumns).keys().value().join(', ')];
_(array).each(function(element, index, list){
csvData.push(_.chain(element).pick(exportColumns).values().value().join(', '));
});
}
@RyanFrench
RyanFrench / Dictionary to Query String.cs
Last active December 17, 2015 13:09
Convert a dictionary of arguments for a web request to a query string
private string ToQueryString(Dictionary<string, string> args)
{
var array = args.Select(x => String.Format("{0}={1}", x.Key, x.Value)).ToArray();
return "?" + string.Join("&", array);
}