Skip to content

Instantly share code, notes, and snippets.

View RickWong's full-sized avatar

Rick Wong RickWong

View GitHub Profile
@halgari
halgari / gist:f431b2d1094e4ec1e933969969489854
Last active May 11, 2024 02:23
What I want from a Type System
The question was asked why I (as a programmer who prefers dynamic languages) don't consider static types "worth it". Here
is a short list of what I would need from a type system for it to be truely useful to me:
1) Full type inference. I would really prefer to be able to write:
(defn concat-names [person]
(assoc person :full-name (str (:first-name person)
(:second-name person))))
And have the compiler know that whatever type required and produced from this function was acceptible as long as the
@avafloww
avafloww / PhpJava.java
Last active April 1, 2025 18:01
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
@rstacruz
rstacruz / µredux.js
Created August 25, 2016 06:24
Redux in <1kb
var INIT = '@redux/INIT'
function createStore (reducer, state, enhancer) {
if (enhancer) return enhancer(createStore)(reducer, state)
var subscribers = []
dispatch({ type: INIT })
return {
@joshdover
joshdover / README.md
Last active September 28, 2023 21:38
Idiomatic React Testing Patterns

Idiomatic React Testing Patterns

Testing React components seems simple at first. Then you need to test something that isn't a pure interaction and things seem to break down. These 4 patterns should help you write readable, flexible tests for the type of component you are testing.

Setup

I recommend doing all setup in the most functional way possible. If you can avoid it, don't set variables in a beforeEach. This will help ensure tests are isolated and make things a bit easier to reason about. I use a pattern that gives great defaults for each test example but allows every example to override props when needed:

@RickWong
RickWong / react.html
Last active April 20, 2021 15:48
Write React apps in 1 HTML file.
<html>
<body>
<div id="react-root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-with-addons.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.5.2/redux.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.7.7/babel.min.js"></script>
<script id="react-app" type="text/template">
const App = ({name}) => {
@RickWong
RickWong / app.js
Last active December 22, 2020 13:37
React without Webpack
const App = ({name}) => {
return (
<h1>Hello {name}</h1>
);
};
ReactDOM.render(<App name="World" />, document.getElementById("App"));

Micro Post: Sneaky Arrow Functions

I was just hacking away on a side project when I wrote this code:

const screencastMock = {
  findOne: () => { }
};
module ImperativeQuickSort (quicksort) where
import Prelude hiding (take,drop,length,tail,init)
import Data.Vector (modify,Vector)
import Data.Vector.Generic.Mutable hiding (modify)
-- | Imperative quicksort with O(log n) auxilary space (on top of returned vector)
quicksort :: Ord a => Vector a -> Vector a
quicksort = modify qsort'
where
@dela3499
dela3499 / blockchain.py
Created March 22, 2016 08:08
Implementation of simple blockchain
import numpy as np
import hashlib
def create_block(parent_block, value, hashfunc):
""" ------------------------------------------------
String -> Block -> (Block -> String) -> Block
------------------------------------------------
Produce a new block from a string value and a hash
of its parent block. In this case, a block is also a string.
"""
// paste in your console
speechSynthesis.onvoiceschanged = function() {
var msg = new SpeechSynthesisUtterance();
msg.voice = this.getVoices().filter(v => v.name == 'Cellos')[0];
msg.text = Object.keys(window).join(' ');
this.speak(msg);
};