Skip to content

Instantly share code, notes, and snippets.

View akulubala's full-sized avatar
🏠
Working from home

Raymond Cheng akulubala

🏠
Working from home
View GitHub Profile
# Make sure you grab the latest version
curl -OL https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-linux-x86_64.zip
# Unzip
unzip protoc-3.2.0-linux-x86_64.zip -d protoc3
# Move protoc to /usr/local/bin/
sudo mv protoc3/bin/* /usr/local/bin/
# Move protoc3/include to /usr/local/include/
@akulubala
akulubala / Laravel-Container.md
Created February 22, 2018 06:32
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

Accessing the Container

let puzzleArr = [];
i = 1;
// 生成包含1 ~ 15数字的数组
for (i; i < 16; i++) {
puzzleArr.push(i)
}
// 随机打乱数组
puzzleArr = puzzleArr.sort(() => {
@akulubala
akulubala / gist:d5c6bd61b941a26dd9a107862c17047e
Created July 8, 2016 03:20
JavaScript数字转换成大写金额
var digitUppercase = function(n) {
var fraction = ['角', '分'];
var digit = [
'零', '壹', '贰', '叁', '肆',
'伍', '陆', '柒', '捌', '玖'
];
var unit = [
['元', '万', '亿'],
['', '拾', '佰', '仟']
];
$strArrays = array_merge(range('a', 'z'), range('AA', 'ZZ'));
echo $strArrays[3]
@akulubala
akulubala / gist:4d4e5868eeaef33a5c62
Created January 24, 2016 17:06
underscore template usage
var tpl = _.template($("#template_errors").html(),{variable: 'items'});// define variable to retrive
var html = tpl(response.responseJSON); //pass datas to be loop
$("#js-form").prepend(html);
// template to use
<script type="text/template" id="template_errors">
<div class="error-list">
<ul>
<% _.each(items,function(item,key,arr) { %>
<li>
mac下使用vim可能会报错,所以这么使用
env EDITOR=nano crontab -e
* * * * * /usr/local/bin/php /path/to/artisan schedule:run 1>> /dev/null 2>&1(需要指定PHP路径)
Ctrl+o 保存cron
Ctrl+x 退出nano
创建 crontab /var/www/cron/xxx.cron ->开始cron保存的位置
@akulubala
akulubala / gist:e9e6b3ed680937259198
Created November 13, 2014 10:03
python 二分查找法
def divid2(array,v):
low = 0
high = len(array)-1
while low<=high:
mid = (low+high)>>1
if v < array[mid]:
high = mid
elif v > array[mid]:
low = mid
else: