Skip to content

Instantly share code, notes, and snippets.

@jimjh
jimjh / jq-select-by-length.sh-session
Created June 18, 2014 16:24
jq - select objects based on lengths of arrays
# objects with at least one widget and at least one user
$ cat part-r-00000 | jq 'select((.widgets | length) > 0 and (.users | length) > 0)'
@jimjh
jimjh / level0.sh
Created February 23, 2014 22:32
level0-java
#!/bin/bash
exec java \
-server \
-Djava.awt.headless=true \
-Xms256M \
-XX:CompileThreshold=1400 \
-Xloggc:./memory.log -verbose:gc -XX:+PrintGCDetails \
-cp out \
jim.SpellCheck \
$@
@jimjh
jimjh / level0.rb
Created February 23, 2014 22:27
Stripe CTF 2014, Level 0
#!/usr/bin/env ruby
# Our test cases will always use the same dictionary file (with SHA1
# 6b898d7c48630be05b72b3ae07c5be6617f90d8e). Running `test/harness`
# will automatically download this dictionary for you if you don't
# have it already.
path = ARGV.length > 0 ? ARGV[0] : '/usr/share/dict/words'
entries = File.read(path).split("\n")
@jimjh
jimjh / Main.java
Created January 15, 2014 17:53
polymorphism
public class Main {
// which method does it invoke?
public static void main(String[] args) {
Object o = "this is a string";
asLong(o);
}
public static void asLong(String s) {
System.out.println("string");
@jimjh
jimjh / mongoid_query.rb
Created July 25, 2013 13:39
mongoid complex query
require 'mongoid'
require 'fabrication'
Mongoid::Config.load_configuration({
sessions: {
default: {
hosts: ['localhost:27017'],
database: 'local'
}
}
@jimjh
jimjh / bug_10865.rb
Last active December 20, 2015 02:38
test script for rails/rails#10865
#!/usr/bin/env ruby
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails', branch: 'master'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@jimjh
jimjh / track.js
Created July 19, 2013 14:15
Event tracking with Google Analytics and LaunchRock.
function conversion(){
var tracker = _gat._createTracker('UA-XXXXXXX-X');
tracker._trackEvent('Users', 'Sign Up');
}
$('.LR-sign-up-submit').click(conversion);
$('.LR-sign-up-input').keypress(function(c) {
(13 == c.which) && conversion();
});
@jimjh
jimjh / github.rb
Created July 12, 2013 15:05
Caching with github_api, faraday-http-cache, and moneta
#!/usr/bin/env ruby
# Usage:
# load './github.rb'
# 10.times { fire }
require 'github_api'
require 'faraday-http-cache'
require 'moneta'
require 'active_support/cache/moneta_store'
require 'logger'
@jimjh
jimjh / github.rb
Created July 9, 2013 22:21
Caching with github_api gem using Faraday middleware.
#!/usr/bin/env ruby
require 'github_api'
require 'faraday-http-cache'
require 'logger'
@store = ActiveSupport::Cache::MemoryStore.new
@github = Github::Repos::Contents.new do |config|
config.stack.insert_before Github::Response::Jsonize, Faraday::HttpCache, @store
end
@jimjh
jimjh / ci
Last active December 19, 2015 05:29
Jenkins script for Karma+Cloudbees
#!/bin/sh
# install nodejs, if using cloudbees
curl -s -o use-node https://repository-cloudbees.forge.cloudbees.com/distributions/ci-addons/node/use-node
NODE_VERSION=0.11.1 source ./use-node
# install phantomjs, karma
[ -d node_modules/phantomjs ] || npm install phantomjs
[ -d node_modules/karma ] || npm install karma