Skip to content

Instantly share code, notes, and snippets.

@zachad
zachad / vanilla-ajax-poll.js
Created April 16, 2018 15:40 — forked from twmbx/vanilla-ajax-poll.js
Polling in JS with an async ajax call that returns a promise ( modified from: https://davidwalsh.name/javascript-polling )
// The polling function
function poll(fn, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
var checkCondition = function(resolve, reject) {
var ajax = fn();
// dive into the ajax promise
ajax.then( function(response){
// If the condition is met, we're done!
@zachad
zachad / autoprune.rb
Last active August 29, 2015 14:05
Example script using the CloudShark search API call to delete capture files older than a certain number of days.
#!/usr/cloudshark/ruby/bin/ruby
#
#
# EXAMPLE CAPTURE PRUNING SCRIPT
#
# This is example code which must be run AT YOUR OWN RISK
# CloudShark is not responsible for any unintended data loss.
# This script is not officially supported by CloudShark or QA Cafe.
#
require 'date'
@zachad
zachad / Gemfile
Last active August 29, 2015 14:01
bundle install --local still tries to connect to rubygems.org
gem "json", "1.8.1"
@zachad
zachad / scrabble_score_test.go
Created May 6, 2014 16:08
Added benchmarks to the scrabble_score exercism test.
package scrabble_score
import "testing"
var tests = []struct {
input string
expected int
}{
{"", 0},
{" \t\n", 0},
@zachad
zachad / json_in_html.html.erb
Created July 16, 2013 03:28
One way to safely escape HTML when writing out JSON objects
<script type='text/javascript'>
var Search = <%= @search.to_json.gsub("/", "\/") %>;
</script>
# big_array has over 120,000 strings in it
def select_search(q)
big_array.select do |s|
s =~ /^#{Regexp.esecap(q)}/
end
end
def grep_search(q)
big_array.grep( /^#{Regexp.escape(q)}/ )