Skip to content

Instantly share code, notes, and snippets.

View jsatk's full-sized avatar
💀

Jesse Atkinson jsatk

💀
View GitHub Profile
// [Sieve of Eratosthenes](http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
var getPrimes = function (max) {
"use strict";
var sieve = [],
primes = [];
for (var i = 2; i <= max; i += 1) {
if (!sieve[i]) {
primes.push(i);
# JS Lint
# Reference: http://blog.simplytestable.com/installing-jslint-for-command-line-use-on-ubuntu/
function jslint {
filename=${1##*/} # Name of file.
dir="/Users/Jesse/Desktop/" # Directory where you want your lint files output. Must be full path. No ~.
path="$dir$filename-lint.js"
/usr/local/bin/node /usr/share/node-jslint/node_modules/jslint/bin/jslint.js "$1" > "$path"
}
(function () {
'use strict';
var doc = this.document,
i, inputs, input, options, rand;
if (!doc.querySelectorAll) return;
inputs = doc.querySelectorAll('input[list]');
@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;
@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 / 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 / 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 / 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 / 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 / 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;