An introduction to curl using GitHub's API
Makes a basic GET request to the specifed URI
curl https://api.github.com/users/caspyin
/** | |
* Gruntfile.js | |
*/ | |
module.exports = function(grunt) { | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
php: { | |
dist: { | |
options: { | |
port: 8080, |
<?php | |
function findMax(array $input, $range) { | |
$curSum = 0; | |
for($i=0;$i<count($input);$i++) { | |
$subArr = array_slice($input, $i, $range); | |
$sum = 0; | |
foreach($subArr as $arr) { | |
$sum += $arr; |
function server() { | |
local port="${1:-8000}" | |
open "http://localhost:${port}/" | |
python -m SimpleHTTPServer "$port" | |
} |
#!/usr/bin/python | |
import os.path | |
import subprocess | |
import sys | |
def get_modified_files(): | |
""" | |
return a list of modified files tracked by git | |
""" | |
git_status = subprocess.Popen(['git', 'status', '-s'], stdout=subprocess.PIPE) |
import urllib2 | |
import json | |
import argparse | |
import sys | |
class HealthCheck(object): | |
""" | |
Parse command line argument | |
""" | |
def parse_arg_options(self): |
<?php | |
// Log down all fatal error | |
register_shutdown_function( function() { | |
$lastError = error_get_last(); | |
if( count($lastError) > 0 ) { | |
Logger::log('Fatal error', implode(',', $lastError)); | |
} | |
}); |
<?php | |
// hex | |
var_dump(0x9fa0ff0b); | |
// 5.2.1 (32bit) | |
// PHP truncates the long | |
int(2147483647) | |
// 5.2.3+ (32bit) |
// clean language contract | |
[1..10].each(|i| puts i); | |
// | |
i = 0; | |
while true do: | |
i = i + 1 | |
if i > 10: | |
break | |
end |
<?php | |
// init connection | |
$pdo = new PDO("mysql:host=localhost;dbname=database", "username", "password"); | |
// Bad bad bad!!! | |
// quote - ecscape + plus quote | |
$username = $pdo->quote($_GET['user']); | |
$pdo->query("SELECT * FROM users where username = $username"); |