Skip to content

Instantly share code, notes, and snippets.

View craigjbass's full-sized avatar
😁

Craig J. Bass craigjbass

😁
View GitHub Profile
class RomanNumerals
def self.to_roman(num)
('I' * num)
.gsub('IIIII', 'V')
.gsub('IIII', 'IV')
.gsub('VV', 'X')
.gsub('VIV', 'IX')
.gsub('XXXXX', 'L')
.gsub('XXXX', 'XL')
.gsub('LL', 'C')
require 'csv'
expectations = []
CSV.foreach("#{__dir__}/expectations2.csv") do |line|
expectations << {
expectation: line[0],
roles: line[4]&.split(','),
description: line[1]
}
class Tennis
def initialize
@player1_score = 'Zero'
@player2_score = 'Zero'
end
def won_point(player)
if player == :player1
@player1_score = next_score_for(@player1_score)
else
class HTTPProductGateway
def find_by(id:)
@id = id
product_for(decode(fetch_product_from_api))
end
private
def product_for(product_payload)

Create three implementations of a simple list data structure:

  • A singly linked list
  • A doubly linked list
  • A list with no form of linking

#Each node has:

Metadata: e.g. link to next node (Metadata can contain anything that you need to make the list work)

Data: a string payload (Data contains only the string payload)

@craigjbass
craigjbass / LukeAndCraig.kt
Last active August 26, 2016 10:42
Code Kata: WordWrap
package uk.co.devls.coffeebook.test.unit
import org.amshove.kluent.`should equal`
import kotlin.test.*
import org.jetbrains.spek.api.Spek
class CodeDojoTest : Spek({
describe("Wrapper") {
it("should return empty string when provided empty string") {
Wrapper().wrap("", 0).`should equal`("")
@craigjbass
craigjbass / ng-angular-element
Created July 11, 2014 13:25
Implements the converse to ng-non-bindable: "ng-bindable" (only compiles mark up within <angular> tags, this is useful for legacy applications which cannot have {'s and }'s escaped easily.)
angular.module( 'ng-angular-element', [] )
.directive( 'angular', function() { return { restrict: 'E' }; } )
.directive( 'html', ['$compile', '$rootScope', '$document',
function( $compile, $rootScope, $document ) {
return {
restrict: 'E',
compile: function(scope, element, attributes) {
angular.forEach( $document.find( 'angular' ), function( angularElement ) {
$compile(angularElement)($rootScope);
} );
@craigjbass
craigjbass / Devls_Enum.php
Last active August 29, 2015 13:56
PHP Enums
<?php
/**
* Enum Abstract Class
*
* Warning: Uses Reflection and LSB. :D
* ==========================================================
*
* To use this class:
*
@craigjbass
craigjbass / Email_Service_Premailer.php
Last active January 2, 2016 00:18
Email_Service_Premailer
<?php
class Email_Service_Premailer {
/**
* Process using premailer
*
* requires:
* yum -y install ruby rubygems ruby-devel
* gem install premailer
* gem install hpricot
@craigjbass
craigjbass / ProjectEuler14.hs
Last active December 30, 2015 10:29
Longest Collatz sequence (Problem 14) http://projecteuler.net/problem=14
module Main (
main
) where
import Data.List (maximumBy)
import Data.Function (on)
collatz 1 = [1]
collatz i = i : (if odd i then collatz $ 3*i + 1 else collatz $ i `div` 2)
main = putStrLn $ show $ maximumBy (compare `on` length) $ map collatz [1..1000000]