Skip to content

Instantly share code, notes, and snippets.

@hugodotlau
hugodotlau / System Design.md
Created December 6, 2019 07:33 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@hugodotlau
hugodotlau / JsonHelper.java
Created December 4, 2012 07:06 — forked from codebutler/JsonHelper.java
Convert Android JSONObject/JSONArray to a standard Map/List.
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.*;
public class JsonHelper {
public static Object toJSON(Object object) throws JSONException {
if (object instanceof Map) {
JSONObject json = new JSONObject();
@hugodotlau
hugodotlau / gist:4031109
Created November 7, 2012 12:07
get random values from model use Yii framework
<?php
#ref: http://www.yiiframework.com/forum/index.php/topic/15298-how-can-i-get-random-values-from-model/page__view__findpost__p__76052
$max = Table::model()->count(array(
'condition' => 'status<:status',
'params' => array('status' => Table::STATUS_A)
));
$offset = rand(0,$max);
@hugodotlau
hugodotlau / FlashBehavior.php
Created September 27, 2012 13:42 — forked from jamband/FlashBehavior.php
Yii Framework: FlashBehavior r3
<?php
/**
* FlashBehavior class file.
*/
class FlashBehavior extends CActiveRecordBehavior
{
/**
* @var string key identifying the flash message
*/
public $key = 'success';
@hugodotlau
hugodotlau / beforeAfter.php
Created September 27, 2012 13:40
Using before and after for transactions
<?php
/**
* @property int $bit_id
*/
class Thing extends CActiveRecord {
}
/**
* @property int $id
@hugodotlau
hugodotlau / gist:3204444
Created July 30, 2012 04:09
Linux/Unix Bash Tips and Tricks
~键盘输入
Ctrl+T:将光标所在处的字符和光标前一字符对调,T,可以理解为Transfer。
Alt+T:交换两个光标当前所处位置单词和光标前一个单词。
Ctrl+U:从光标所在处开始删除字符,直到行首;u,可以理解为undo光标前所有输入。
Ctrl+Y:恢复Ctrl+U删除的字符;y,可以理解为vim里的yank(复制)。
Ctrl+?:删除所有字符,比Ctrl+U强。
Ctrl+K:从光标所在处开始删除字符,直到行尾。
Ctrl+W:删除最后一个单词;W,Word。
@hugodotlau
hugodotlau / gist:3121449
Created July 16, 2012 08:01
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@hugodotlau
hugodotlau / gist:2988041
Created June 25, 2012 11:24
Yii 批量更新范例
<?php
public function actionBatchUpdate($id)
{
$model = Product::model()->findByPk($id);
$items=Retailprice::model()->findAllByAttributes(array('product_id'=>$id));
if(isset($_POST['Retailprice']))
{
$valid=true;
@hugodotlau
hugodotlau / gist:2893372
Created June 8, 2012 03:27
ipfilter form array()
<?php
/**
* Checks to see if the user IP is allowed by {@link ipFilters}.
* @param string $ip the user IP
* @return boolean whether the user IP is allowed by {@link ipFilters}.
*/
protected function allowIp($ip)
{
foreach ($this->ipFilters as $filter)
{
<?php
/**
* A class for true random hash string generation.
*/
class RandHash
{
/**
* @param string $prefix to be used with uniqid()
* @return string hash
*/