Skip to content

Instantly share code, notes, and snippets.

Avatar

Farley Lai farleylai

View GitHub Profile
@farleylai
farleylai / Markdium-TypeScript.ts
Created Jul 6, 2019
Markdium-Hello Markdium!
View Markdium-TypeScript.ts
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 Jul 6, 2019
Markdium-Hello Markdium!
View Markdium-Diff.diff
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 Sep 2, 2015
Sample Interview Question: Print the spiral given a 2D array
View PrintSpiral.groovy
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 Aug 29, 2015
Toolchain file for CMake cross-compilation.
View arm-linux-gnueabihf.cmake
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 Nov 19, 2015
A Complete build.gradle for the Experimental Android Gradle Plugin
View build.gradle
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 Oct 6, 2015
A bottom up approach to the Numbers Game by Devdraft
View NumberGame.java
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);
View AbsTest.java
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);
}
View testMovingAvg.java
@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 Aug 29, 2015
Though Java 8 introduces the Optional class to improve readability and prevent NullPointerException, implicit performance overhead in inevitable in the following test cases.
View JavaOptionalTest.java
public class JavaTest {
long nanos;
@Before
public void setUp() {
System.gc();
nanos = System.nanoTime();
}
@After