Skip to content

Instantly share code, notes, and snippets.

@jayzeng
jayzeng / gruntfile.js
Created June 17, 2013 00:32
php grunt task From http://chrsm.org/
/**
* Gruntfile.js
*/
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
php: {
dist: {
options: {
port: 8080,
@jayzeng
jayzeng / findmax.php
Created June 11, 2013 06:09
Find max
<?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;
@jayzeng
jayzeng / server.sh
Created June 11, 2013 05:49
server function from paul irish
function server() {
local port="${1:-8000}"
open "http://localhost:${port}/"
python -m SimpleHTTPServer "$port"
}
@jayzeng
jayzeng / curl.md
Created May 27, 2013 01:59 — forked from btoone/curl.md

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@jayzeng
jayzeng / syntax_check.py
Created May 25, 2013 03:14
syntax check for modified puppet template and manifests
#!/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)
@jayzeng
jayzeng / healthcheck.py
Last active December 17, 2015 10:29
health check
import urllib2
import json
import argparse
import sys
class HealthCheck(object):
"""
Parse command line argument
"""
def parse_arg_options(self):
@jayzeng
jayzeng / fatal_error.php
Created March 5, 2013 06:34
fatal error
<?php
// Log down all fatal error
register_shutdown_function( function() {
$lastError = error_get_last();
if( count($lastError) > 0 ) {
Logger::log('Fatal error', implode(',', $lastError));
}
});
@jayzeng
jayzeng / dex_to_dec.php
Last active December 14, 2015 11:38
hex to decimal in php
<?php
// hex
var_dump(0x9fa0ff0b);
// 5.2.1 (32bit)
// PHP truncates the long
int(2147483647)
// 5.2.3+ (32bit)
@jayzeng
jayzeng / language_design.rb
Created January 30, 2013 07:31
language design
// clean language contract
[1..10].each(|i| puts i);
//
i = 0;
while true do:
i = i + 1
if i > 10:
break
end
@jayzeng
jayzeng / sql injection.php
Last active December 11, 2015 22:39
sql injection
<?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");