Skip to content

Instantly share code, notes, and snippets.

// get a collapsed operations array
private function collapseOperations($operations) {
// setup a glossary of operations categorized by name
$glossary = parseOperationsByName($operations);
// serialize leftover operations
$result = [];
foreach ($glossary as $operation) {
$result = array_merge($result, $operation);
@hguochen
hguochen / 1_phpunit-api.md
Created March 27, 2016 05:28 — forked from loonies/1_phpunit-api.md
PHPUnit Cheat Sheet

PHPUnit API reference

  • version 3.6

TODO

Check those constraints:

$this->anything()
@hguochen
hguochen / gist:2b8084c87f29537f9e4a
Created February 22, 2016 21:05
Testing rcid experiment distribution for GFM fb story titles experiment
var rcids = [
"283960cdf44044c08e41881c9cd25d10",
"039e574bf9314c9bbc334f85de28a227",
"8443c8026cd847efb31fe36181687998",
"cb407b75cfe146f98af5b6427fa29983",
"13d70696cdae465b97aa5277c2ca7057",
"4cac4982f16f4d6799be5c622cbb5603",
"5c1af928e10a42f780c53446698a8020",
"db7ae9817c674e3d8bd804f28cd0e054",
"fc9f392ab712414183631971cccc8a0a",
@hguochen
hguochen / print_matrix_spiral.py
Last active August 29, 2015 14:27
Print a 2d matrix in spiral format from outwards to inwards
#Write a function that takes a matrix and examines each item in a spiral order, printing each item as it comes to it.
#For example, given a matrix like this as input:
#[[11, 12, 13, 14, 15],
#[21, 22, 23, 24, 25],
#[31, 32, 33, 34, 35],
#[41, 42, 43, 44, 45]]
#Your program must print:
@hguochen
hguochen / smallest_range_integers
Created April 3, 2015 06:03
Find smallest range in k sorted integers
"""
input:
List 1: [4, 10, 15, 24, 26]
List 2: [0, 9, 12, 20]
List 3: [5, 18, 22, 30]
# size of each list? 10,000
# each list have at least 1 item
output: [20,24] <-- diff of 4
@hguochen
hguochen / reST documentation format
Last active August 29, 2015 14:10
reST style documentation format
"""
This is a reST style.
:param param1: this is a first param
:param param2: this is a second param
:returns: this is a description of what is returned
:raises keyError: raises an exception
"""
{
"files":
{
"jquery" : "http://code.jquery.com/jquery.js",
"jquery.min" : "http://code.jquery.com/jquery.min.js",
"jquery-cookie" : "https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js",
"jquery-dotimeout" : "https://raw.github.com/cowboy/jquery-dotimeout/master/jquery.ba-dotimeout.min.js",
"jquery-extra-selectors" : "https://raw.github.com/keithclark/JQuery-Extended-Selectors/master/jquery-extra-selectors.js",
"jquery-flexslider" : "https://raw.github.com/mbmufffin/FlexSlider/master/jquery.flexslider-min.js",
"jquery-mediaelement" : "https://raw.github.com/johndyer/mediaelement/master/build/mediaelement-and-player.js",
-module(merge_sort).
-export([merge_sort/1]).
% bottom-up merge sort
merge_sort([]) ->
[];
merge_sort(L) ->
iterate([[X] || X <- L]).
iterate([Xs]) ->
import models
class PersonManager(models.Manager):
@models.querymethod
def male(query):
return query.filter(gender='m')
@models.querymethod
@hguochen
hguochen / Django formset with AJAX
Last active January 15, 2018 08:23
Django formset with ajax
<h3>My Services</h3>
{{ serviceFormset.management_form }}
{% for form in serviceFormset.forms %}
<div class='table'>
<table class='no_error'>
{{ form.as_table }}
</table>
</div>
{% endfor %}
<input type="button" value="Add More" id="add_more">