Skip to content

Instantly share code, notes, and snippets.

View marcusshepp's full-sized avatar
🎯
Focusing

Marcus Shepherd marcusshepp

🎯
Focusing
View GitHub Profile
@marcusshepp
marcusshepp / got_m.py
Last active June 18, 2016 23:50
got moves specific migration function
def foo(apps, _):
Category = apps.get_model("main", "MoveCategory")
for i, name in enumerate(DEFAULT_CATEGORY_NAMES):
category = Category.objects.create(**{
"name": name,
"description": "",
"one_handed": i % 2 == 0,
"number_of_packets": None,
})
category.save()
@marcusshepp
marcusshepp / check_args.sh
Created June 19, 2016 18:22
checking if any args match a string when running a script
for i in "$@" ; do # for all args
if [[ $i == "boot" ]]; then # if arg equals this string
# do this
bash ~/projects/dollars/as/django/bootserver.sh
break
fi
done
@marcusshepp
marcusshepp / clear_selection.js
Created June 21, 2016 18:37
clear selection on an element if it gets highlighted
function clear_selection() {
/*
I use this to ensure the `next` and `prev` buttons don't
stay highlighted when clicking quickly.
*/
if(document.selection && document.selection.empty){
document.selection.empty();
} else if (window.getSelection){
var sel = window.getSelection();
sel.removeAllRanges();
@marcusshepp
marcusshepp / left_index.js
Created June 21, 2016 18:38
cool js function I wrote to determine the left index of a photo carousel
function determine_left_index(len){
/*
If the number of locations doesn't divide equally
into three perform a function on that number that
will determine the index we should point to.
Example:
len = 20 // twenty photo objects
len % 3 == 0 // returns false, 20 does not divide equally into 3
len/3 // returns 6.666...
(len/3)|0 // returns 6 which says we have six screens of three photos
@marcusshepp
marcusshepp / oneliner.sh
Created June 21, 2016 19:53
grep for a string in git log, use awk to print the hash from the result, use the hash to git show the diff
git show $(git log --oneline | grep SSO$ | awk 'FNR == 2 {print $1}')
@marcusshepp
marcusshepp / how_many_lines.sh
Last active June 21, 2016 20:30
print how many lines of code in a project recursively
# where .py is the extention to search on
( find ./ -name '*.py' -print0 | xargs -0 cat ) | wc -l
# also,
wc -l **/*rb
# also, this counts every line of every file
grep '' -R . | wc -l
# wc will print the number of lines in a file or multiple files
@marcusshepp
marcusshepp / visited_attractions.js
Created June 21, 2016 20:43
visited attractions
function init_visited_attractions(){
/*
Visited Attractions.
Displays the destinations that the current User has visited on the map.
If the user has completed the map and chose to `restart` the visited
attractions feature will stay populated with all the attractions on the
map while the user continues to log activity.
Displays each `screen` as three seperate photos/locations/attractions.
See Redmine ticket #4449 for more information.
*/
@marcusshepp
marcusshepp / index.html
Created June 23, 2016 23:32
filtering and searching with ng-repeat
<div ng-repeat="cm in classic_moves | filter:classic_moves_query | orderBy:'date_created'">{{ cm.name }}</div>
@marcusshepp
marcusshepp / protect_me.sh
Last active June 24, 2016 14:30
protecting a remote branch from local repos
# In a senario where you need changes done
# on a branch. But the remote repository
# has a lot of clones that should NOT see
# the changes happening on the branch in
# question. Then `transfer.hiderefs`
# is the answer to your problem.
# Create the protected branch on your local repo.
# This will be the branch that no other repo
@marcusshepp
marcusshepp / read-write.sh
Created June 24, 2016 15:26
giving a user read-write access to a directory
sudo chmod -R 666 path/to/dir