Skip to content

Instantly share code, notes, and snippets.

View blogscot's full-sized avatar

Iain Diamond blogscot

View GitHub Profile
@blogscot
blogscot / generators3.py
Created May 12, 2016 13:37
Comparing JS and Py Generators
# function *foo(x) {
# var y = 2 * (yield (x + 1));
# var z = yield (y / 3);
# return (x + y + z);
# }
#
# var it = foo( 5 );
#
# // note: not sending anything into `next()` here
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@blogscot
blogscot / xml_parsing.ex
Last active December 1, 2018 17:49
A first look at XML parsing using Elixir
defmodule XmlParsing do
import Record, only: [defrecord: 2, extract: 2]
defrecord :xmlElement, extract(:xmlElement, from_lib: "xmerl/include/xmerl.hrl")
defrecord :xmlText, extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl")
def xml do
"""
<html>
<head>
@blogscot
blogscot / dict.elm
Created August 23, 2016 13:45
Experimenting with Elm Dictionaries
import Html exposing (text, div, br)
import Dict exposing (Dict)
times3 : Maybe Int -> Maybe Int
times3 x =
case x of
Just num -> Just <| num * 3
_ -> Nothing
@blogscot
blogscot / SimpleApp.scala
Created November 18, 2016 12:37
The hello word for Apache Spark
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
object SimpleApp {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Simple Application")
val sc = new SparkContext(conf)
@blogscot
blogscot / ping-pong.ex
Created January 18, 2017 21:39
A Ping Pong example between a local and remote machine
defmodule Table do
@moduledoc """
Plays Ping Pong between a local and remote machine.
Start both machines using short names:
iex --sname node1 --cookie fudge
iex --sname node2 --cookie fudge
"""
@blogscot
blogscot / .eslintrc
Created August 13, 2017 12:47
My starter Eslint configuration
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": ["react", "prettier"],
@blogscot
blogscot / myPinkTruck.js
Last active November 19, 2021 03:53
Factory Pattern examples using ES6 syntax
class Car {
constructor(doors = 4, state = "brand new", color = "silver") {
this.doors = doors
this.state = state
this.color = color
}
}
class Truck {
@blogscot
blogscot / enum.js
Created August 31, 2017 12:11
A basic JavaScript Enum constructor function
// A basic Enum constructor function
const Enum = (...values) => {
let newEnum = {}
for (const value of values) {
Object.assign(newEnum, {
[value]: value
})
}
return newEnum
}
@blogscot
blogscot / visitor.rs
Last active April 27, 2018 18:01
Visitor Pattern Example in Rust
///
/// Each car element accepts a visitor.
///
trait CarElement {
fn accept(&self, visitor: &CarElementVisitor);
}
///
/// Each visitor must deal with each element of a car.
///
trait CarElementVisitor {