Skip to content

Instantly share code, notes, and snippets.

@huydx
huydx / AMD.js
Created April 14, 2013 00:34
AMD
define(["alpha"], function (alpha) {
return {
verb: function(){
return alpha.verb() + 2;
}
};
});
@huydx
huydx / gist:5329449
Created April 7, 2013 07:35
scala coursera course week 2
package funsets
import common._
/**
* 2. Purely Functional Sets.
*/
object FunSets {
/**
* We represent a set by its characteristic function, i.e.
@huydx
huydx / wordle_solver.go
Created January 28, 2022 14:23
wordle_solver.go
package main
import (
"bufio"
"fmt"
"github.com/umpc/go-sortedmap/desc"
"log"
"math/rand"
"os"
"strconv"
//go:noescape
//go:linkname memhash runtime.memhash
func memhash(p unsafe.Pointer, h, s uintptr) uintptr
type stringStruct struct {
str unsafe.Pointer
len int
}
// MemHash is the hash function used by go map, it utilizes available hardware instructions(behaves
@huydx
huydx / interesting.scala
Last active May 12, 2020 05:52
scala interesting code
def twoPermutation[T](l: List[T)) = {
l flatMap { a =>
l flatMap { b =>
if (a==b)
Nil
else
List(a,b)
}
}
}

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@huydx
huydx / facebook_weird.js
Created September 18, 2014 04:12
facebook_weird.js
5000, "channel_manual_reconnect_defer_msec": 2000,
"sound.notif_ogg_url": "https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/yT\/r\/q-Drar4Ade6.ogg",
"sound.notif_mp3_url": "https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/yb\/r\/VBbzpp2k5li.mp3",
"sound.ringtone_mp3_url": "https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/yq\/r\/Mpd0-fRgh5n.mp3",
"sound.ringtone_ogg_url": "https:\/\/fbstatic-a.akamaihd.net\/rsrc.php\/y3\/r\/mbcn6dBHIeX.ogg",
"24h_times": false,
"roger.seen_delay": 15000
},
12],
["SystemEventsInitialData", [], {
@huydx
huydx / visualizer.js
Created May 5, 2013 14:51
visualizer.js
(function(){
window.onload = init;
function init() {
var context = new webkitAudioContext();
var audiobuffer;
var sourceNode;
var analyzer;
window.javascriptnode = null;
@huydx
huydx / valid.js
Created November 29, 2012 17:54
javascript url validation regex
/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|
# Path to your oh-my-zsh installation.
export ZSH=/Users/jp20992/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="jnrowe"
# Uncomment the following line to use case-sensitive completion.