Skip to content

Instantly share code, notes, and snippets.

View blogscot's full-sized avatar

Iain Diamond blogscot

View GitHub Profile
@blogscot
blogscot / eviscerate-sequence_test.clj
Created April 20, 2022 21:31
Discord Server: Clojure Study Group Solution #1
(ns eviscerate-sequence-test
(:require [clojure.test :refer [deftest is run-tests]]))
(defn eviscerate-sequence
([xs n] (eviscerate-sequence xs n n))
([xs n m]
(let [v (vec xs)]
(concat (subvec v 0 n) (subvec v (inc m))))))
(deftest eviscerate-sequence-test
@blogscot
blogscot / data.csv
Created August 5, 2019 12:26
Creating a HTML table from CSV data using D3
car name miles/gallon cylinders displacement horsepower weight acceleration model year origin
chevrolet chevelle malibu 18 8 307 130 3504 12 70 1
buick skylark 320 15 8 350 165 3693 11.5 70 1
plymouth satellite 18 8 318 150 3436 11 70 1
@blogscot
blogscot / index.html
Created May 15, 2019 12:00
An example of how to use Vue Slot Props
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>VueJS</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
@blogscot
blogscot / basicBlockChain.kt
Created December 1, 2018 16:17
An basic Blockchain example in Kotlin
import com.google.gson.GsonBuilder
import java.security.MessageDigest
import java.util.Date
// This example is a port of the Java version described by:
// https://medium.com/programmers-blockchain/create-simple-blockchain-java-tutorial-from-scratch-6eeed3cb03fa
typealias BlockChain = ArrayList<Block>
@blogscot
blogscot / shipBuilding.kt
Created November 26, 2018 23:08
Example of the Builder pattern using Kotlin
class Ship {
var name: String = ""
var crewSize: Int = 0
var numMasts: Int = 0
override fun toString(): String {
return "Ship { Name: $name, Num masts: $numMasts Crew Size: $crewSize}"
}
}
@blogscot
blogscot / huffmanEncoding.kt
Created November 22, 2018 13:57
A Kotlin implementation of Huffman Encoding
import java.util.PriorityQueue
// node class is the basic structure
// of each node present in the huffman - tree.
class HuffmanNode : Comparable<HuffmanNode> {
var freq = 0
var chr = ' '
var left: HuffmanNode? = null
var right: HuffmanNode? = null
@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 {
@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 / 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 / .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"],