Skip to content

Instantly share code, notes, and snippets.

@farleylai
farleylai / Markdium-TypeScript.ts
Created July 6, 2019 07:16
Markdium-Hello Markdium!
let foo = 'bar'
/**
Don't worry about the code block, it will be saved as a gist with right language format, and auto embed to your post.
**/
@farleylai
farleylai / Markdium-Diff.diff
Created July 6, 2019 07:16
Markdium-Hello Markdium!
public class Hello1
{
public static void Main()
{
- System.Console.WriteLine("Hello, World!");
+ System.Console.WriteLine("Rock all night long!");
}
}
@farleylai
farleylai / PrintSpiral.groovy
Last active September 2, 2015 23:23
Sample Interview Question: Print the spiral given a 2D array
void printSpiral(A, int r, int c, int rows, int cols) {
if(A == null || rows < 1 || cols < 1) {
System.out.println();
return;
}
if(rows == 1) {
for(int i = 0; i < cols; i++)
print(A[r][c+cols-1-i] + " ");
} else if(cols == 1) {
for(int i = 0; i < rows; i++)
@farleylai
farleylai / arm-linux-gnueabihf.cmake
Last active August 29, 2015 14:26
Toolchain file for CMake cross-compilation.
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc -mfloat-abi=hard)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++ -mfloat-abi=hard)
set(CMAKE_AR arm-linux-gnueabihf-ar CACHE FILEPATH "Archiver")
# where is the target environment
@farleylai
farleylai / build.gradle
Last active November 19, 2015 06:55
A Complete build.gradle for the Experimental Android Gradle Plugin
apply plugin: 'com.android.model.application'
def MSB = ['AutoCor', 'BitonicSort', 'BitonicSortRecursive', 'FFT2', 'FFT3', 'FIR', 'FIRcoarse', 'FMRadio']
MSB << 'MatrixMult' << 'MatrixMultBlock' << 'MergeSort' << 'Repeater'
MSB << 'BeepBeep' << 'MFCC' << 'Crowd'
model {
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
@farleylai
farleylai / NumberGame.java
Last active October 6, 2015 06:00
A bottom up approach to the Numbers Game by Devdraft
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class NumbersGame {
public static final boolean DEBUG = false;
public static final BigInteger ONE = BigInteger.ONE;
public static final BigInteger TWO = BigInteger.valueOf(2);
public static void debug(String line) {
if(DEBUG) System.err.println(line);
public class AbsTest {
public static int absSpec(int x) {
return x < 0 ? -x : x;
}
public static int absImpl(int x) {
int signbits = x >> 31;
int xor = x ^ signbits;
return xor + (signbits & 0x01);
}
@Test
public void testMovingAvg() throws IOException {
Log.i("========= %s ===========\n", INFO.getMethodName());
SFG sfg = new SFG();
Channel AB = sfg.link("A", "B", 1, 10, 1);
Channel BC = sfg.link("B", "C", 1, 1, 1);
sfg.save(INFO.getMethodName(), true);
sfg.annotate("A", AB, CREATE, 1);
sfg.annotate("B", BC, CREATE, 1);
@farleylai
farleylai / JavaOptionalTest.java
Last active August 29, 2015 14:02
Though Java 8 introduces the Optional class to improve readability and prevent NullPointerException, implicit performance overhead in inevitable in the following test cases.
public class JavaTest {
long nanos;
@Before
public void setUp() {
System.gc();
nanos = System.nanoTime();
}
@After