Skip to content

Instantly share code, notes, and snippets.

View rohanthewiz's full-sized avatar

Rohan Allison rohanthewiz

  • Texas
View GitHub Profile
@rohanthewiz
rohanthewiz / EastOrientedwithMethodChaining.rb
Created December 23, 2014 18:02
Example of East Oriented programming via Method Chaining
class Car
def initialize(color, make, model)
@color, @make, @model = color, make, model
# new implicitly returns self
end
def color; puts @color; self; end
def make; puts @make; self; end
@rohanthewiz
rohanthewiz / channels_and_waitgroups.go
Created December 10, 2015 07:14
Using channels and waitgroups for effective communication with goroutines
package main
import (
"fmt"
"sync"
)
// Send words onto a channel until we receive on the done channel
func emit(wch chan string, dch chan struct{}, wg *sync.WaitGroup) {
words := []string{"The", "quick", "brown", "fox"}
@rohanthewiz
rohanthewiz / SassMeister-input.scss
Created December 18, 2015 04:45
Generated by SassMeister.com.
// ----
// libsass (v3.3.2)
// ----
.asset-edit-table {
width: 100%;
&__row {
width: 100%;
}
&__left-side {
@rohanthewiz
rohanthewiz / go_templates.go
Created January 17, 2016 08:29
Exercising Go templates
package main
import (
"fmt"
"html/template"
"os"
"strings"
)
type Person struct {
Name string
@rohanthewiz
rohanthewiz / SassMeister-input.scss
Created February 15, 2016 20:41
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
$acolor: rgba(#040708, 0.76);
@function rgba_blend($fore, $back) {
$ored: ((1 - alpha($fore)) * red($back) ) + (alpha($fore) * red($fore));
$ogreen: ((1 - alpha($fore)) * green($back) ) + (alpha($fore) * green($fore));
$oblue: ((1 - alpha($fore)) * blue($back) ) + (alpha($fore) * blue($fore));
@rohanthewiz
rohanthewiz / SassMeister-input.scss
Last active February 15, 2016 20:48
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
// Blend colors with alpha channel to solid color
@function rgba_blend($fore, $back) {
$ored: ((1 - alpha($fore)) * red($back) ) + (alpha($fore) * red($fore));
$ogreen: ((1 - alpha($fore)) * green($back) ) + (alpha($fore) * green($fore));
$oblue: ((1 - alpha($fore)) * blue($back) ) + (alpha($fore) * blue($fore));
@return rgb($ored, $ogreen, $oblue);
# A Pattern for Custom Exception types
module Orders
class OrdersError < StandardError; end
class OrdersLineItemError < OrdersError
def message
'There was a line item error.'
end
end
@rohanthewiz
rohanthewiz / scratch_2.go
Created March 16, 2017 17:30
Split and trim a string containing any combination of tabs and spaces into trimmed words
ackage main
import (
"fmt"
"strings"
)
func main() {
str := "When not ok\t, val\tis 0"
fmt.Printf("%q\n", SplitAndTrim(str))
@rohanthewiz
rohanthewiz / main.go
Created March 16, 2017 17:44
Golang: Sum, sort, and print values by User from data given in a file
package main
import (
"os"
"fmt"
"io/ioutil"
"strings"
"regexp"
"strconv"
"sort"
@rohanthewiz
rohanthewiz / go_concurrency_pattern.go
Last active April 12, 2017 22:06
A Pattern for concurrency using Wait Groups and Buffered Channels
// A Concurrency Pattern using Wait Groups and Buffered Channels
package main
import (
"time"
"fmt"
"sync"
)
// Synopsis