Skip to content

Instantly share code, notes, and snippets.

View jiaweizhang's full-sized avatar

Jiawei Zhang jiaweizhang

View GitHub Profile
anonymous
anonymous / adder.v
Created April 26, 2016 03:05
4 bit by 4 bit binary multiplier
module adder(A, B, Sum);
input [3:0]A, B;
output [4:0]Sum;
wire [2:0]carry;
halfadder(A[0], B[0], Sum[0], carry[0]);
fulladder(A[1], B[1], carry[0], Sum[1], carry[1]);
fulladder(A[2], B[2], carry[1], Sum[2], carry[2]);
fulladder(A[3], B[3], carry[2], Sum[3], Sum[4]);
endmodule
@hyle
hyle / ko.utils.3.4.0.signatures.js
Last active September 25, 2018 09:12
KnockoutJS 3.4.0 / 3.4.1 / 3.4.2 utils (ko.utils) signatures
// knockout 3.4.0
ko.utils.addOrRemoveItem = function (array, value, included) { /* .. */ }
ko.utils.anyDomNodeIsAttachedToDocument = function (nodes) { /* .. */ }
ko.utils.arrayFilter = function (array, predicate) { /* .. */ }
ko.utils.arrayFirst = function (array, predicate, predicateOwner) { /* .. */ }
@soheilhy
soheilhy / nginxproxy.md
Last active March 22, 2024 08:54
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@mariussoutier
mariussoutier / Mail.scala
Created August 23, 2012 12:13
Sending mails fluently in Scala
package object mail {
implicit def stringToSeq(single: String): Seq[String] = Seq(single)
implicit def liftToOption[T](t: T): Option[T] = Some(t)
sealed abstract class MailType
case object Plain extends MailType
case object Rich extends MailType
case object MultiPart extends MailType
@jboner
jboner / latency.txt
Last active May 6, 2024 07:06
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@lazywithclass
lazywithclass / gist:1402456
Created November 28, 2011 22:49
Fibonacci tail recursion in Java
public static long tailRecursive(long n) {
if (n <= 2) {
return 1;
}
return tailRecursiveAux(0, 1, n);
}
private static long tailRecursiveAux(long a, long b, long count) {
if(count <= 0) {
return a;