Skip to content

Instantly share code, notes, and snippets.

View lawliet89's full-sized avatar
πŸ§‘β€πŸ€β€πŸ§‘
He/him

Yong Wen Chua lawliet89

πŸ§‘β€πŸ€β€πŸ§‘
He/him
View GitHub Profile
@lawliet89
lawliet89 / Dockerfile
Last active July 25, 2020 06:22
Yarn Example Test Code for #1750
FROM node:7.1
# Install yarn
RUN set -x \
&& curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install yarn
WORKDIR /src/app
@lawliet89
lawliet89 / save.sh
Created September 19, 2016 09:45
Bash Script to build and save `docker-compose` service to tar.gzip
#!/bin/bash
set -euo pipefail
print_usage() {
echo "usage: save.sh [-o|--output output.tar.gz] service_name"
}
main() {
PRINT_USAGE=0
@lawliet89
lawliet89 / test.fsx
Last active June 17, 2016 18:38
F# Functional Signatures Exercise
// See https://fsharpforfunandprofit.com/posts/function-signatures/
// val testA = int -> int
// val testB = int -> int -> int
// val testC = int -> (int -> int)
// val testD = (int -> int) -> int
// val testE = int -> int -> int -> int
// val testF = (int -> int) -> (int -> int)
// val testG = int -> (int -> int) -> int
// val testH = (int -> int -> int) -> int
@lawliet89
lawliet89 / exercises.fs
Created February 16, 2016 02:25
F# Programming Exercises
open System
let bigFib n =
let rec loop previous previousPrevious = function
| n when n = 0I -> previousPrevious
| n -> loop (previous + previousPrevious) previous (n - 1I)
loop 1I 0I n
let factorial n =
let rec loop acc = function
public static string BytesToString(long byteSize)
{
const string format = "{0} {1}";
const int orderBase = 1024;
var units = new[] {"B", "KB", "MB", "GB", "TB", "PB", "EB"};
if (byteSize == 0)
return "0 B";
var order = Convert.ToInt32(Math.Floor(Math.Log(byteSize, orderBase)));
var rescaledSize = Math.Round(byteSize/Math.Pow(orderBase, order), 1);
@lawliet89
lawliet89 / gist:f8836618cec706c82dcc
Last active February 15, 2016 08:29
Tail recursive Fibonacci Sequence
open System
// Tail recursive Fibonacci
// BigInt -> BigInt
let bigFib n =
let rec loop previous previousPrevious = function
| n when n = 0I -> previousPrevious
| n -> loop (previous + previousPrevious) previous (n - 1I)
loop 1I 0I n
@lawliet89
lawliet89 / WebBrowserExtensions.cs
Last active October 12, 2022 13:06
Calling Javascript Object Method in a System.Windows.Forms.WebBrowser Contorl
using System;
using System.Linq;
using System.Web.Script.Serialization;
using System.Windows.Forms;
namespace AsynchronousWebPage
{
/// <summary>
/// Extension convenience methods to invoke arbitrary Javascript method on a web page
/// hosted by a WebBrowser control.
@lawliet89
lawliet89 / SuperStack.cs
Created February 16, 2015 13:07
HackerRank Super Stack Solution
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Solution
{
class Solution
{
static void Main(string[] args)
@lawliet89
lawliet89 / Volleyball.cs
Created February 16, 2015 13:06
HackerRank Volleyball Match Solution
using System;
namespace Solution
{
// Algorithm discussion at https://www.hackerrank.com/challenges/volleyball-match/editorial referenced
// (Not enough time to develop algorithm!)
class Solution
{
public const int Modular = 1000000007;
@lawliet89
lawliet89 / gist:9677319
Created March 21, 2014 00:54
OpenCL Inline PTX for 256 Bits unsigned addition & multiplication
// Credits: http://goo.gl/NtaADC
// Inline PTX assembly
uint add_asm(uint *result, const uint *a, const uint *b) {
uint carry;
asm("{\n\t"
"add.cc.u32 %0, %9, %17; \n\t"
"addc.cc.u32 %1, %10, %18; \n\t"
"addc.cc.u32 %2, %11, %19; \n\t"
"addc.cc.u32 %3, %12, %20; \n\t"