Skip to content

Instantly share code, notes, and snippets.

@hanbzu
hanbzu / tdd-quotes-beck-dhh.md
Created April 16, 2020 20:09
Some quotes about Test Driven Development (TDD) from DHH and Kent Beck.

Some quotes about Test Driven Development (TDD) from DHH and Kent Beck. They made a debate video or something. Source: https://martinfowler.com/articles/is-tdd-dead/

Code is not complete without tests, but that doesn't mean you need to write your tests first -- DHH

Examples, think of examples. Work from specific to general. But maybe not everybody is like that. -- Kent Beck

A design insight can allow you to do more fine-grained testing. -- Kent Beck

@hanbzu
hanbzu / stream_concat.scala
Created November 6, 2013 14:18
Scala: Stream concatenation. Thanks to Pavel Lepin.
val a = Stream(1)
//a: scala.collection.immutable.Stream[Int] = Stream(1, ?)
def b: Stream[Int] = Stream(b.head)
//b: Stream[Int]
a #::: b
//res0: scala.collection.immutable.Stream[Int] = Stream(1, ?)
a append b
@hanbzu
hanbzu / usbstartup.sh
Created December 26, 2013 17:19
Linux/Ubuntu: USB startup disk through the command line
# The Ubuntu USB startup creator often crashes.
# This is an alternate way of doing the same process through the command line
# First plug in the USB pendrive. It will mount automatically
# Then check where it is (which device)
df
# Let's say we see it's in /dev/sdb1
# Then we have to use /dev/sdb and NOT /dev/sdb1
@hanbzu
hanbzu / index.js
Last active May 2, 2021 08:14
Proposal for a React component with state managed by actions and a reducer.
import React, { Component } from 'react'
import initialState from './initialState.js'
import reducer from './reducer.js'
export class Layout extends Component {
state = initialState
reduce = (action) =>
this.setState(reducer(action, this.state))
@hanbzu
hanbzu / getdeeplink.js
Last active June 5, 2020 07:52
Small script to create a deep link for Chrome users. Copy the URL, copy the text and pass it to the script.
@hanbzu
hanbzu / water_pouring.scala
Created November 4, 2013 13:16
Scala: water pouring problem solution
class Pouring(capacity: Vector[Int]) {
// States
type State = Vector[Int]
val initialState = capacity map (x => 0)
// Moves
trait Move {
// A method that defines state changes
def change(state: State): State
@hanbzu
hanbzu / useThrottle.js
Created November 11, 2019 17:11
A React hook that throttles a value
import React from "react";
export default function useThrottle(val, ms) {
const [throttledVal, setThrottledVal] = React.useState(val);
const latestVal = React.useRef(val);
React.useEffect(() => {
latestVal.current = val;
}, [val]);

If you're feeling lost in React land check these wonderful resources:

  • Thinking in React. Create an app from scratch in a few minutes to understand the mindset behind React. Absolutely recommended.

  • Basic theorethical concepts Sebastian Markbåge's attempt to documment the thinking on UI building that inspired React. Spoiler: React will be gone at some point, but these are important concepts that are here to stay.

  • React patterns. Great summary of the patterns that are often used throughout React apps. Going over these will get you up to speed pretty fast.

Remember, to play with React great sandboxes are CodeSandbox or a new project created with the Create React App generator.

@hanbzu
hanbzu / add_methods_to_exising_classes.scala
Created November 25, 2013 11:52
Scala: Pattern to add missing methods to already existing classes.
// Here we add the 'userInput' method to the Future class
implicit class FutureCompanionOps(f: Future.type) extends AnyVal {
def userInput(message: String): Future[String] = Future {
readLine(message)
}
}
// Without the sintactic sugar:
class FutureCompanionOps(f: Future.type) extends AnyVal {
def userInput(message: String): Future[String] = Future {
@hanbzu
hanbzu / ui_demoing_with_animated_gif.md
Last active February 1, 2018 15:02
UI demoing with animated GIFs

This walkthrough explains how to prepare animated GIF images of UI interactions for the purpose of demoing. I'm assuming a MacOS setup but this could also be useful for other setups.

Note: If your GIFs will be just a few seconds long you can use a MacOS app called GIPHY capture.

Tooling

We'll be using Quicktime Player for video recording, ffmpeg for video conversion and gifsicle to generate the animated GIFs. Let's first install the tooling:

brew install ffmpeg