Skip to content

Instantly share code, notes, and snippets.

View jsatk's full-sized avatar
💀

Jesse Atkinson jsatk

💀
View GitHub Profile
@jsatk
jsatk / longestPrefix.js
Created December 15, 2014 18:27
Finds the longest prefix in an array of strings
var longestPrefix = function (arr) {
var firstString = arr[0],
prefix = '';
for (var i = 0; i < firstString.length; i++) {
for (var j = 1; j < arr.length; j++) {
if (arr[j].charAt(i) !== firstString.charAt(i)) {
return prefix;
}
}
var start, end, diff, splitString, nativeArray;
splitString = function () {
return 'foo bar baz bing ding dong lars foo bar baz bing ding dong lars foo bar baz bing ding dong lars foo bar baz bing ding dong lars foo bar baz bing ding dong lars foo bar baz bing ding dong lars'.split(' ');
};
nativeArray = function () {
return ['foo', 'bar', 'baz', 'bing', 'ding', 'dong', 'lars', 'foo', 'bar', 'baz', 'bing', 'ding', 'dong', 'lars', 'foo', 'bar', 'baz', 'bing', 'ding', 'dong', 'lars', 'foo', 'bar', 'baz', 'bing', 'ding', 'dong', 'lars', 'foo', 'bar', 'baz', 'bing', 'ding', 'dong', 'lars', 'foo', 'bar', 'baz', 'bing', 'ding', 'dong', 'lars'];
};
@jsatk
jsatk / Prompts
Created October 29, 2014 23:22
My bash and fish shell prompts
# For Bash. Photo here: http://i.jsatk.us/image/403u443G2k06
PS1="\n\[$RESET\]┌─▪\[\e]2;$PWD\[\a\]\[\e]1;\]$(basename "$(dirname "$PWD")")/\W\[\a\]\[${BOLD}${MAGENTA}\]\u \[$WHITE\]on \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$RESET\]\n└─▪ "
# For Fish. Photo here: http://i.jsatk.us/image/1Z0m132j181I
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
echo
set_color magenta
@jsatk
jsatk / uniqueCharsInString.js
Last active August 29, 2015 14:06
Counts the unique characters in a string
var uniqueCharsInStringCounter = function (string) {
var countOfChars = {}, numberCountAndUniqueChars = '', chars, uniqueChars;
if (!string || typeof string !== 'string') {
throw new Error('Must call method with a string as an argument.');
}
chars = string.split('').sort();
uniqueChars = chars.filter(function (char, index, array) {
return array.indexOf(char) === index;
@jsatk
jsatk / keybase.md
Created August 14, 2014 17:16
Keybase.io Proof

Keybase proof

I hereby claim:

  • I am jsatk on github.
  • I am jsatk (https://keybase.io/jsatk) on keybase.
  • I have a public key whose fingerprint is 06D4 7A7E FE77 2731 0F67 075A 01BD 80DF DC5A C6E4

To claim this, I am signing this object:

@jsatk
jsatk / Preferences.sublime-settings
Created April 22, 2014 20:59
Sensible Default SublimeText Preferences
{
"always_show_minimap_viewport": true,
"auto_complete_commit_on_tab": true,
"caret_style": "phase",
"draw_minimap_border": true,
"ensure_newline_at_eof_on_save": true,
"highlight_line": true,
"ignored_packages":
[
"Vintage",
@jsatk
jsatk / clipboard_manipulation.rb
Last active August 29, 2015 13:57
Replaces your clipboard with an underscore delimited string. Throw in your ~/Library/Scripts/ directory and `chmod a+x`.
#!/usr/bin/ruby
# Save file to a directory in your $PATH.
# Ensure it is executable `chmod a+x clipboard_manipulation.rb`.
#
# Usage `copy some text like this`.
# Then from the commandline run `clipboard_manipulation.rb space underscore`.
# Your clipborad will now contain the text `copy_some_text_like_this`.
#
# This is a simply and silly script that scratched an itch I was having.
@jsatk
jsatk / unfuckopenwith
Created February 25, 2014 21:31
Fixes OS X's 'Open With…' dialogue
# For Bash Shell
# Fix the shitty OS X Open With menu duplicates
function fixopenwith() {
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user
killall Finder
echo 'Open With has been rebuilt, Finder will relaunch'
}
# For Fish Shell http://fishshell.com
function fixopenwith --description 'Fix the shitty OS X Open With menu duplicates'
@jsatk
jsatk / ArrowJumpTo.js
Created February 17, 2014 03:28
Adds basic arrow navigation to your site. Easy to change and customize. Ideal for blog or article-based websites. jQuery is required, although I may make a jQuery-less version soon.
var ArrowJumpTo = function (event, elements) {
var keyCheck,
scrollToElement,
getElementPositions,
getPositionToScrollTo;
keyCheck = function (event, elements) {
if ([38, 40].indexOf(event.keyCode) === -1) return false;
var els = elements || event.data.element;
@jsatk
jsatk / fuckYouIWantMyShitOnTop.js
Last active December 31, 2015 02:29
For when you really want your shit on top.
var fuckYouIWantMyShitOnTop = function (idOfElementYouWantOnTop) {
var all = document.getElementsByTagName("*"),
maxZIndex = 9007199254740992, // https://gist.github.com/jsatk/7921133#comment-968150
i, highestZIndex, currentZIndex, currentEl;
for (i = all.length - 1; i >= 0; i--) {
currentEl = all[i];
currentZIndex = Number(currentEl.style.zIndex);
if (isNaN(currentZIndex)) continue;