Skip to content

Instantly share code, notes, and snippets.

@raym
raym / followScroll.js
Last active August 29, 2015 14:07
javascript for having a sidebar element follow you as you scroll -- behavior modeled after facebook sidebar
var wrapperId = 'sidebarWrapperIdOnPage';
var
$w = $(window),
$wrap = $('#'+wrapperId),
followerInitialOffset = $wrap.offset().top,
marginTop = 0,
$wrap, windowTop, windowBottom, followerHeight,
followerTop, followerBottom, followerBottomPosition
;
@raym
raym / browerDetect.js
Last active August 29, 2015 14:08
Browser detection
var
is_chrome = navigator.userAgent.indexOf('Chrome') > -1,
is_safari = navigator.userAgent.indexOf("Safari") > -1 && !is_chrome,
is_firefox = navigator.userAgent.indexOf('Firefox') > -1,
is_explorer = (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0),
is_opera = navigator.userAgent.indexOf("Presto") > -1
;
@raym
raym / selectionDirection.js
Created November 6, 2014 04:47
Determine direction currently selected text was selected (rtl vs ltr)
var selectionIsRTL = function(sel) {
sel = sel || document.getSelection();
position = sel.anchorNode.compareDocumentPosition(sel.focusNode);
return (
// nodes are same if position === 0
// selection direction is RTL if anchorOffset > focusOffset
!position && sel.anchorOffset > sel.focusOffset ||
// focus preceeds anchor
position === Node.DOCUMENT_POSITION_PRECEDING
)
@raym
raym / synchsafe.js
Last active February 27, 2024 07:40
synchsafe conversion functions
/*
Synchsafe integers are used in ID3 tags
http://id3.org/id3v2.4.0-structure (6.2)
https://en.wikipedia.org/wiki/Synchsafe
The why of synchsafe:
http://stackoverflow.com/a/5652842
Example:
255 (%11111111) encoded as a 16 bit synchsafe integer is 383 (%00000001 01111111).
@raym
raym / cherry_pick_commits_commands
Created February 6, 2015 01:44
commands run to move the last 4 commits to a different branch via cherry pick
git log -4 | grep 'commit' | awk '{print $2}' | tail -r > commits.txt
git co destination_branch
for commit in $(cat commits.txt); do git cherry-pick $commit; done
git log -4
@raym
raym / i_think_mogrify_am.sh
Last active August 29, 2015 14:15
sweet imagemagick uses
# convert all png's in a directory to jpg
mogrify -format jpg *.png
@raym
raym / ubuntu_free_boot_space.sh
Last active August 29, 2015 14:16
for when ubuntu /boot needs more space because it's filled with old images
# you're in a dark room, it's 2 am, and you're
# updating ubuntu via Software Updater, when you get the error:
# Not enough free disk space on disk '/boot'
# what do you do? try this:
# edit: it seems like this one command accomplishes the same thing as the rest, and removes even more unneeded packages
audo apt-get autoremove
# if that doesn't work for some reason, try the original gist revision's steps:
uname -r
@raym
raym / anandroidfilenameconventionconverter.sh
Created March 29, 2015 20:02
mv all files in a directory with a particular extension -- remove dashes, underscores, spaces, dots (add more if you like) and lowercase the filename
#!/bin/bash
ext=.png
for file in *$ext; do
baseName=${file%$ext}
baseNoDashes=$(echo $baseName | tr -d '_- .')
baseLower=$(echo $baseNoDashes | tr '[:upper:]' '[:lower:]')
fileNew=$baseLower$ext
echo Renaming $file to $fileNew
@raym
raym / bcrypt_fix.sh
Created March 30, 2015 00:20
upstart meteor node npm bcrypt invalid elf header fix
#!/bin/bash
# if when looking in /var/log/upstart/yourapp.log, you find the error:
# Error: /home/yourapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/build/Release/bcrypt_lib.node: invalid ELF header
# at Error (native)
# at Module.load (module.js:355:32)
# at Function.Module._load (module.js:310:12)
# at Module.require (module.js:365:17)
# at require (module.js:384:17)
@raym
raym / rename_remote_branch.sh
Created April 5, 2015 18:42
rename a branch that you've pushed to a remote
git push origin :oldname
git branch -m oldname newname
git push origin newname