Skip to content

Instantly share code, notes, and snippets.

@bobpace
bobpace / checkForTickets
Created April 27, 2013 17:39
Script to check blizzcon ticket site until tickets are available.
#!/bin/ruby
require 'open-uri'
url = "http://us.blizzard.com/store/blizzcon-tickets.xml"
ticketsAvailable = false
begin
contents = open(url).read
unless contents =~ /Currently unavailable/
`start #{url}`
@bobpace
bobpace / fizzbuzz.scala
Last active January 2, 2016 18:59
fizzBuzzer in scala
def fizzBuzzer(entries: Map[Int, String])(nums: Seq[Int]) = {
def fizzBuzzify(n: Int) =
(n, entries collect { case (key, value) if n % key == 0 => value })
nums map fizzBuzzify collect {
case (num, words) if !words.isEmpty => num + ": " + words.mkString(" ")
}
}
val answer = fizzBuzzer(Map(3 -> "fizz", 5 -> "buzz"))(0 to 100)
@bobpace
bobpace / prime-stream.scala
Last active January 2, 2016 18:59
streams
lazy val primes: Stream[Int] =
2 #:: Stream.from(3).filter(n => primes.takeWhile(p => p * p <= n).forall(p => n % p > 0))
lazy val fib: Stream[BigInt] = 0 #:: 1 #:: fib.zip(fib.tail).map { case(x,y) => x + y }
@bobpace
bobpace / ExampleTests.cs
Last active January 3, 2016 05:19
Testing Rx Observables
[TestFixture]
public class ExampleTests : InteractionContext<Example>
{
private List<string> _inputs;
private TestSchedulers _schedulerProvider;
[SetUp]
public void Setup()
{
_inputs = new List<string>
@bobpace
bobpace / rx-random-interval.js
Created March 18, 2015 23:23
Random interval observable
var Rx = require('rx');
var _ = require('lodash');
module.exports = function(minSeconds, maxSeconds) {
if (minSeconds >= maxSeconds) {
throw new Error('min needs to be less than max');
}
var getDueTime = () => _.random(minSeconds, maxSeconds) * 1000;
@bobpace
bobpace / react-slider.jsx
Created March 18, 2015 23:28
React Slider with Rx Observable implementation of drag and drop
var React = require('react');
var Input = require('react-bootstrap/src/Input');
var Glyphicon = require('react-bootstrap/src/Glyphicon');
var _ = require('lodash');
var Rx = require('rx');
var canUseDom = require('can-use-dom');
var changeCase = require('change-case');
function events(event) {
return canUseDom ? Rx.Observable.fromEvent(document, event) : Rx.Observable.empty;
@bobpace
bobpace / multiselect.jsx
Last active August 29, 2015 14:17
React MultiSelect with item filter
var React = require('react');
var Input = require('react-bootstrap/src/Input');
var DropdownButton = require('react-bootstrap/src/DropdownButton');
var _ = require('lodash');
var escape = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;
function escapeRegExp(str) {
return str.replace(escape, "\\$&");
};
@bobpace
bobpace / event-stream.js
Created March 18, 2015 23:35
Koa.js server sent events with Rx Observables
module.exports = function eventStream() {
return function *(next) {
this.req.setTimeout(0); //no timeout
this.type ='text/event-stream; charset=utf-8';
this.set('Cache-Control', 'no-cache');
this.set('Connection', 'keep-alive');
this.set('Transfer-Encoding', 'chunked');
yield* next;
}
@bobpace
bobpace / curl-proxy.js
Last active August 29, 2015 14:17
Koa.js curl proxy with ntlm authentication
var spawn = require('child_process').spawn;
var eventStream = require('./event-stream');
var compose = require('koa-compose');
//get username / password from somewhere
var username = ...;
var password = ...;
var credential = username + ':' + password;
//8 hour timeout
@bobpace
bobpace / lodash-flatmap-mixin.js
Created March 18, 2015 23:44
Flatmap for lodash
var _ = require('lodash');
module.exports.apply = function lodashFlatMapMixin() {
function flatMap (array, selector) {
return [].concat.apply([], array.map(selector));
};
_.mixin({flatMap: flatMap}, {chain: true});