Skip to content

Instantly share code, notes, and snippets.

View yuanqing's full-sized avatar

Yuan Qing Lim yuanqing

View GitHub Profile
@yuanqing
yuanqing / gist:4fc10d752c292e096a78
Last active August 29, 2015 14:03
PHP: Empty, Isset, Count
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
empty($undefined); #=> true
isset($undefined); #=> false
@count($undefined); #=> 0
$null = null;
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
# error
use Foo;
use Bar\Foo; # cannot use Bar\Foo as Foo because the name is already in use
# ok
@yuanqing
yuanqing / gist:77296383313cd758e8fa
Created July 17, 2014 20:25
Installing an older version of PHP (5.3) on OSX
$ curl -s http://php-osx.liip.ch/install.sh | bash -s 5.3
$ /usr/local/php5/bin/php -v
$ sudo ln -s /usr/local/php5/bin/php /usr/bin/php53
$ php53 -v
@yuanqing
yuanqing / gist:3814bf30367017a30448
Last active August 29, 2015 14:04
File/Directory Terminology
# File
- filePath: '/foo/bar/baz.qux'
- fileName: 'baz.qux'
- dirPath: '/foo/bar'
- dirName: 'bar'
- baseName: 'baz'
- extension: 'qux'
# Directory
@yuanqing
yuanqing / frontmatter.php
Created July 21, 2014 02:53
PHP: Parsing YAML Frontmatter
<?php
# 10,000 iterations in 1.9696619510651s
function frontMatterExplode($str)
{
$lines = explode(PHP_EOL, $str);
if (rtrim($lines[0]) === '---') {
unset($lines[0]);
$i = 1;
$yaml = array();
0000
00 00
00 00
00 00
0000
1111
11
11
11
@yuanqing
yuanqing / Common Lisp.sublime-build
Created August 14, 2014 15:32
Building Common Lisp in Sublime Text
{
"cmd": ["sbcl", "--load", "$file"]
}
@yuanqing
yuanqing / gist:87bceacedde4dbd96fab
Last active March 28, 2023 18:10
Sublime Text: Wrap Selection in Backticks
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`${0:$SELECTION}`"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
]
}
@yuanqing
yuanqing / gist:c5d4fdb2859a34f971e9
Created August 22, 2014 08:12
ANSI C: Variable Shadowing
#include <stdio.h>
int main()
{
int i = 1;
printf("%d\n", i); //=> 1
{
printf("%d\n", i); //=> 1
int i = 2;
printf("%d\n", i); //=> 2
@yuanqing
yuanqing / gist:eca80df6e07da03536b3
Created September 14, 2014 06:42
`git commit` + `git push` in a single command
function gp() {
git commit -m '$1'
if [ "$#" -eq 2 ]; then
git push origin $2
else
git push origin master
fi
}
$ gp 'foo bar'