Skip to content

Instantly share code, notes, and snippets.

View jarrettmeyer's full-sized avatar

Jarrett Meyer jarrettmeyer

View GitHub Profile
describe User do
# The test suite adds a #stub() method to every object. Since instances of objects
# and class definitions are considered objects in Ruby, the #stub() method gets
# applied just about everywhere. It can be used to stub both instance methods and
# class methods.
it "can have tests that hit a database" do
user = User.find(1) # This test will go to the database
expect(user.username).to eq("admin")
@jarrettmeyer
jarrettmeyer / Controller.cs
Created July 10, 2014 12:58
Unit testing a controller
// Version 0: Nope.
public class SomeController
{
public object Get(string story, string view)
{
// Unit test blows up on the following line because there
// is no Request (NullReferenceException) from within a
// unit test.
var queryString = Request.RequestUri.ParseQueryString();
// snip
@jarrettmeyer
jarrettmeyer / CookieUtil.js
Last active August 29, 2015 14:04
Login View Example
CookieUtil = (function () {
var expirationDays = 14;
function deleteCookie(key) {
var expiration = new Date(0).toGMTString();
document.cookie = key + "=;expires=" + expiration;
}
function getCookie(key) {
public class TryParseInt32Result
{
private readonly bool _isSuccessful;
private readonly int _value;
public TryParseInt32Result(bool isSuccessful, int value)
{
_isSuccessful = isSuccessful;
_value = value;
}
/**
* Load a collection of products from a data store.
* @param {array} productIds - Array of product IDs.
* @param {function} load - Function to load a product by ID, e.g. fetch from API, etc.
* @param {function} done - Done callback, to be fired when all products are loaded.
*/
function loadProducts(productIds, load, done) {
// Set up vars that we will need in this function.
var numberOfProductIds = productIds.length;
@jarrettmeyer
jarrettmeyer / singleton_test.js
Created February 20, 2015 12:57
Singleton Tests
var assert = require('assert');
describe('how not to make a singleton', function () {
var a, b;
beforeEach(function () {
a = { message: "Hello, World!" };
b = { message: "Hello, World!" };
});
@jarrettmeyer
jarrettmeyer / pubsub
Last active March 2, 2016 20:46
pubsub with NodeJS and AMQPLib
#!/usr/bin/env node
//
// Example of publisher/subscriber pattern in NodeJS, with AMQPLib. This program has been
// demonstrated to work with 500k messages and 4 subscribers.
//
// #WorksOnMyMachine
//
// Usage: ./pubsub
//
@jarrettmeyer
jarrettmeyer / .gitignore
Last active August 29, 2015 14:20
Cradle Bulk Insert Test
.idea/
node_modules/
*.stderr
*.stdout
@jarrettmeyer
jarrettmeyer / insert_data.py
Last active April 8, 2022 07:10
Inserting data into HBase with Python
#!/usr/bin/env python
"""
Insert data into HBase with a Python script.
To create the table, first use the hbase shell. We are going to create a
namespace called "sample_data". The table for this script is called "rfic",
as we will be inserting Request for Information Cases from the City of
Indianapolis.
@jarrettmeyer
jarrettmeyer / threaddemo.js
Created March 3, 2016 11:27
multiple threads in a NodeJS application
'use strict';
const args = process.argv;
const cluster = require('cluster');
function getThreads() {
let threads = 1;
let tag = args.indexOf('--threads');
if (tag > 0) {
let newThreads = parseInt(args[tag + 1], 10);