Skip to content

Instantly share code, notes, and snippets.

@nickjacob
nickjacob / scrollend.coffee
Created March 30, 2015 15:50
fake event for on iphone scroll end
# this should be x-browser check
_raf = window.requestAnimationFrame
isScrolling = (fn) ->
pageY = window.pageYOffset
_checker = ->
unless (fn(pageY != window.pageYOffset) is false)
pageY = window.pageYOffset
_raf(_checker)
_raf(_checker)
@nickjacob
nickjacob / define_method.coffee
Last active August 29, 2015 14:17
define_method in coffeescript
class ContentItem
constructor: (@type) ->
# implementation of ruby's
# `define_method`; simplifies
# metaprogramming/adding methods at runtime
@define_method: (name, fn) ->
# syntax shorthand for
# this.prototype[name] = function(/* arguments */){...}
# note that `fn` will be in instance context (bound)
@nickjacob
nickjacob / pre-commit.sh
Last active April 11, 2022 22:06
Pre-commit hook to check for extra-large files that you probably shouldn't have in version control
#!/usr/bin/env bash
echo "================================================================================"
echo " PRE-COMMIT: CHECKING FILE SIZES"
echo "================================================================================"
# constant that you want to check sizes against
SIZE_LIMIT=$(( 1048576 * 64 ))
# $1 - filetype
function invalid_filetype() {
@nickjacob
nickjacob / moderation_example.rb
Created July 1, 2014 22:48
image moderation example
require 'crowdmoderation'
API_KEY = "your_api_key"
DOMAIN_BASE = "https://api.crowdmoderation.net"
job_id = "your_job_id"
CrowdModeration::Job.connect! API_KEY, DOMAIN_BASE
job = CrowdModeration::Job.new(job_id)
unit = CrowdModeration::Unit.new(job)
@nickjacob
nickjacob / mirador_example.rb
Last active August 29, 2015 14:03
mirador api usage example
require 'mirador'
mc = Mirador::Client.new('your_key_here')
mc.classify_files('bathing-suit.jpg', 'nsfw-user-upload.png').each do |result|
puts "#{ result.name }: #{ (result.safe and 'is' or 'is not' } safe"
end
mc.classify_urls('http://possibly-nsfw.com/cool.png').each do |result|
puts "#{ result.name }: #{ (result.safe and 'is' or 'is not' } safe"
end
@nickjacob
nickjacob / systemd-prblm.service
Last active March 17, 2023 16:11
execute arbitrary bash code/variable substitution in systemd units
[Unit]
Description=Demonstrate Bash
[Service]
ExecStartPre=/usr/bin/bash -c "/usr/bin/systemctl set-environment MYVAR=$(( 2 + 2 ))"
ExecStart=/usr/bin/echo "2 + 2 = ${MYVAR}"
@nickjacob
nickjacob / upgrade_starcluster.sh
Created March 22, 2014 23:39
script to safely upgrade starcluster & dependencies
#!/usr/bin/env bash
# upgrade starcluster
####
mute_run ()
{
$* >/dev/null 2>&1
}
cecho ()
{
@nickjacob
nickjacob / leveldb_merge.pl
Created March 13, 2014 08:07
merge a series of level dbs to provide an output db of a specified length
#!/usr/bin/env perl
use strict;
use warnings;
use Tie::LevelDB;
sub foreach_key {
my ($db_name, $block) = @_;
my $db = new Tie::LevelDB::DB($db_name);
my $it = $db->NewIterator;
@nickjacob
nickjacob / coinbase-price
Created January 28, 2014 20:46
check and update buy/sell price on coinbase
#!/usr/bin/env ruby
# get coinbase price
###
require 'coinbase'
require 'optparse'
# your API key - https://coinbase.com/docs/api/authentication
COINBASE_API = ''
UP_ARROW = "\u25B2".encode('utf-8')
DOWN_ARROW = "\u25BC".encode('utf-8')
@nickjacob
nickjacob / label-output.sh
Created January 24, 2014 05:44
bash function to prepend text to output of script (example use in here too)
function label_stream()
{
perl -sne '$|=1; print "[$cmd]\t$_"' -- -cmd="$1"
}
# example use
ls -lafh . | label_stream "ls"
# output
[ls] drwxr-xr-x 6 nickjacob staff 204B Nov 11 2012 Processing/