Skip to content

Instantly share code, notes, and snippets.

View yuanqing's full-sized avatar

Yuan Qing Lim yuanqing

View GitHub Profile
obj
len
arr
elem
opts
fn
acc

How to Code

  • Flat over nested
  • Simple over complex
  • Referential transparency over stateful
  • Explicit over implicit/magic
  • A smaller/shorter program is a better program
  • Maintainability over being terse/parlour tricks
  • Concrete over abstract
  • Modular over monolithic; modules over frameworks/libraries
'use strict';
var str = 'foobarbaz';
var regexp = /bar/;
console.log(str.match(regexp)); //=> [ 'bar', index: 3, input: 'foobarbaz' ]
console.log(regexp.exec(str)); //=> [ 'bar', index: 3, input: 'foobarbaz' ]
console.log(regexp.test(str)); //=> true
#!/bin/bash
# File names.
SRC_FILE="$1.ml"
TEST_FILE="test.ml"
EXEC_FILE="test.out"
# Exit if no module name specified.
[ -z "$1" ] && echo "$0: $src: Need a module name" >&2 && exit 1
int main() {
int arr[2] = { 1, 2 };
int* x = &arr[0]; // x = address of arr[0]
printf("%d, %d\n", *x, arr[0]); //=> 1, 1
arr[0] = 24;
printf("%d, %d\n", *x, arr[0]); //=> 24, 24
*x = 42;
.active
.affix
.alert
.alert-danger
.alert-dismissable
.alert-info
.alert-link
.alert-success
.alert-warning
.arrow
# SINGLE-QUOTED
# text between the single-quotes is read as a plain string
$ echo 'foo "bar" `baz`'
foo "bar" `baz`
# BACK-QUOTED
# text between the back-quotes is read as a command
$ echo `echo "foo"`
foo
import java.util.*;
import java.io.*;
class ReadInputByCharacter {
public static void main(String[] args) throws Exception {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
function error() {
echo "foo: $1"
exit 1
}
# loop over arguments
while [ $# -gt 0 ]; do
case "$1" in
# flag with value
-c | -r | -i | -o)
#!/bin/sh
error() {
echo "foo: $1"
exit 1
}
while [ $# -gt 0 ]; do
case "$1" in
-v)