Skip to content

Instantly share code, notes, and snippets.

View rockarts's full-sized avatar
💭
🐝 🇨🇦

Steven Rockarts rockarts

💭
🐝 🇨🇦
  • Edmonton, AB
View GitHub Profile
@rockarts
rockarts / standard_deviation.rb
Created June 24, 2014 03:07
Class For Calculating the Standard Deviation of Arrays
require 'minitest/autorun'
# Test case provided by: http://en.wikipedia.org/wiki/Standard_deviation
class TestStandardDeviation < MiniTest::Unit::TestCase
def setup
@values = [2, 4, 4, 4, 5, 5, 7, 9]
end
def test_average_is_calculated
average = @values.inject{ |memo, element| memo + element} / @values.length
@rockarts
rockarts / TuesdaysCounter.rb
Last active August 29, 2015 14:03
This will fail for any month except the current month but will get the amount of Tuesdays in the current month.
require 'minitest/autorun'
require 'date'
class TestWeekdayCounter < MiniTest::Unit::TestCase
def test_number_of_tuesdays_in_june_2014_should_be_4
thisMonth = Date.new(2014, 6, 1)
nextMonth = Date.new(2014, thisMonth.month + 1, 1) - 1
assert_equal 4, WeekdayCounter.new.get_tuesdays(thisMonth, nextMonth)
end
require 'minitest/autorun'
class TestDeck < MiniTest::Unit::TestCase
def test_that_deck_has_52_cards
deck = Deck.new
assert_equal 52, deck.cards.count
end
def test_that_deck_is_shuffled
var Firebase = require('firebase');
var json2html = require('node-json2html');
const api = new Firebase('https://hacker-news.firebaseio.com/v0')
var topStoryIds = []
function loadTopStories(callback) {
api.child('topstories').on('value', snapshot => {
topStoryIds = snapshot.val();
callback(print_stories);
@rockarts
rockarts / base58.cs
Last active August 7, 2016 21:05
Base58 Encode
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void ShouldEncodeIntegerToBase58()
@rockarts
rockarts / UrlRepository.cs
Created August 7, 2016 21:37
Simple In-Memory Repo for Testing
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
namespace UnitTestProject1
{
[TestClass]
public class UrlRepositoryTest
{
[TestMethod]
public void ShouldAddKeyAndRetrieveKey()
@rockarts
rockarts / IndexWords.swift
Created February 3, 2017 21:42
Index Words by First Letter in Swift
func buildIndexFromNames(names: [String]) -> [String:[String]] {
var indexedNames: [String:[String]] = [String():[]]
for name in names{
let firstLetterOfString = String(name.characters.prefix(1)).uppercaseString
if indexedNames[firstLetterOfString] != nil {
indexedNames[firstLetterOfString]!.append(name)
} else {
indexedNames[firstLetterOfString] = [name]
@rockarts
rockarts / setup.swift
Created February 20, 2017 17:19
Setup UIActivityLoadingIndicator
func setupLoadingIndicator() {
indicator.color = UIColor .blackColor()
indicator.frame = CGRectMake(0.0, 0.0, 10.0, 10.0)
indicator.center = self.view.center
self.view.addSubview(indicator)
indicator.bringSubviewToFront(self.view)
indicator.startAnimating()
}
func loadTable() {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
//Add your long running task to get the table data here
dispatch_async(dispatch_get_main_queue()) {
self.indicator.stopAnimating()
self.indicator.hidesWhenStopped = true
self.tableView.reloadData()
}
}
@rockarts
rockarts / gist:43acd0c382a571c2965d9e58cdca5211
Last active March 10, 2017 18:41
Polygon Map Test Data
Border of Polygon
-115.103760,50.958427,0.0
-115.982666,51.103522,0.0
-116.290283,51.323747,0.0
-116.323242,51.563412,0.0
-115.982666,51.638476,0.0
-115.576172,51.549751,0.0
-114.895020,51.337476,0.0
-114.763184,51.013755,0.0
-115.081787,50.958427,0.0