Skip to content

Instantly share code, notes, and snippets.

View iocat's full-sized avatar
:octocat:
you're a lizard, Perry.

Thanh Ngo iocat

:octocat:
you're a lizard, Perry.
  • CA
View GitHub Profile
@iocat
iocat / Streams.res
Created May 16, 2021 03:08
Some Stream utilities in Rescript.
let map = (stream, functor) =>
Stream.from(_ =>
try Some(stream->Stream.next->functor) catch {
| Stream.Failure => None
}
)
let keep = (stream, predicate) =>
Stream.from(_ => {
let rec getNext = () => {
@iocat
iocat / index.tsx
Last active November 23, 2020 04:03
State Management without Redux but with useReducer/useContext.
// Reproduced in TSX from blog :P https://blog.logrocket.com/use-hooks-and-context-not-react-and-redux/
export type ExampleAction1 = {
type: 'ACTION'
}
export type ExampleAction2 = {
type: 'ACTION2'
}
export type Action = ExampleAction1 | ExampleAction2;
@iocat
iocat / getLocalIdent.js
Last active January 14, 2019 22:03
Stateful variable-length CSS Modules' class name generator (using ECMAScript Generator Function)
// @flow
/**
* Copyright (c) 2019-present, Thanh Ngo.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
@iocat
iocat / flyd-react.js
Created November 17, 2018 07:05
Simple high order function that connects flyd streams/callback functions to React
// Example
// const counter = flyd.stream()
// const incCounter = () => counter(counter() + 1)
// const FComp = ({counter, incCounter}) => <span onClick={incCounter}> {counter} </span>
// connectStreams ({
// counter,
// incCounter
// })(FComp)
//
@iocat
iocat / Lambda.java
Created June 9, 2018 02:40
Lambda expression in Java
import java.util.function.*;
public class Lambda {
public static void main(String[] args) {
// In the object world of Java when everything is an object, you can't really pass function as "object."
//
//
//
// Unlike Java <1.8, Javascript allows you to have first-class functions or function as value which you can
@iocat
iocat / introrx.md
Created April 14, 2018 15:45 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@iocat
iocat / deleteinstances.sh
Created April 5, 2018 01:58
Remove all EC2 instances on the currently selected region (set up with aws configure)
INSTANCES=`aws ec2 describe-instances | grep InstanceId | awk '{ print $2 }' | tr -d '",'`
for INSTANCE in $INSTANCES; do
aws ec2 modify-instance-attribute --no-disable-api-termination --instance-id $INSTANCE
aws ec2 terminate-instances --instance-ids $INSTANCE
done
package edu.rutgers.cs431.teamchen.trafficgen;
import edu.rutgers.cs431.TrafficGeneratorProto.Car;
import edu.rutgers.cs431.TrafficGeneratorProto.GateAddress;
import edu.rutgers.cs431.TrafficGeneratorProto.TimeRequest;
import edu.rutgers.cs431.TrafficGeneratorProto.TimeResponse;
import edu.rutgers.cs431.teamchen.util.SystemConfig;
import java.io.IOException;
import java.net.InetAddress;
@iocat
iocat / resource-loader.go
Last active September 1, 2017 06:53
A simple Gopherjs resource loader for dynamic resources added to the head of the document
// Package resloader loads resources and invokes a single callback for all packages
// useful for checking availability of loaded resources on the fly or all at once
package resloader
import (
"errors"
"path/filepath"
"time"
"github.com/gopherjs/gopherjs/js"