Skip to content

Instantly share code, notes, and snippets.

var fs = require('fs'),
http = require('http'),
https = require('https'),
express = require('express'),
token = '',
bodyParser = require('body-parser'),
request = require('request');
var port = 443;
@aloha1003
aloha1003 / Logstash configure for parse json from text file
Created June 22, 2016 02:58
Logstash configure for parse json from text file
filter {
grok {
match => { "message" => "^\[%{TIMESTAMP_ISO8601:datetime}\]\s+%{DATA:env}\s+%{LOGLEVEL:loglevel}+\:%{GREEDYDATA:log_msg}" }
add_field => {
"received_at" =>"%{datetime}"
"enviroment" => "%{env}"
"log_level" => "%{loglevel}"
}
}
@aloha1003
aloha1003 / gist:cb074b94a625e6790ccbde48fde2f5e2
Created July 28, 2016 15:43 — forked from mgedmin/gist:9547214
Setting up a Jenkins slave on Linux
# This is how you add a Jenkins slave
# On master:
sudo -u jenkins -H ssh-keygen
# On slave
adduser --system --group --home=/var/lib/jenkins-slave --no-create-home --disabled-password --quiet --shell /bin/bash jenkins-slave
install -d -o jenkins-slave -g jenkins-slave /var/lib/jenkins-slave
String.prototype.format = String.prototype.f = function() {
var s = this,
i = arguments.length;
while (i--) {
s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
}
return s;
};
//UseAge
String.prototype.format = String.prototype.f = function() {
var s = this,
i = arguments.length;
var compareStr = '';
var map = {};
if ( (arguments.length == 1) && (typeof arguments[0] === 'object')) {
for (var prop in arguments[0]) {
key = prop;
compareStr += key+'|';
map['{'+key+'}'] = arguments[0][prop];
def downLoadImage(region, imageObj):
s3 = boto3.resource('s3', region_name=region)
bucketName = str(imageObj["Bucket"])
objectName = str(imageObj["Object"])
key = s3.Bucket(bucketName) \
.Object(objectName)
saveFileName = '/tmp/'+objectName.replace('/', '__')
s3.meta.client.download_file(bucketName, objectName, saveFileName)
return saveFileName
@aloha1003
aloha1003 / gist:47285c267bbca39e7ff9e6d4ab3c5b30
Created September 8, 2016 01:27 — forked from prime31/gist:5675017
Simple PHP script showing how to send an Android push notification. Be sure to replace the API_ACCESS_KEY with a proper one from the Google API's Console page. To use the script, just call scriptName.php?id=THE_DEVICE_REGISTRATION_ID
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
try {
//do something
} catch (\Exception $ex){
//Write to Log
echo $ex->getMessage();
}
<?php
//Enter your code here, enjoy!
function arrayListPointer(...$index): Closure{
$item = array_shift($index);
$composeIndex = count($index) > 0 ? arrayListPointer(...$index) : function($x) {
return $x;
};
return function($x) use ($item, $composeIndex) {
return '['.$item.']'.$composeIndex($x);
};
@aloha1003
aloha1003 / custom
Last active February 26, 2017 06:45
動態調整validation 規則
<?php
class Model extends BaseModel {
public $defaultRuleAry = []; //預設規則
public function validation() { //驗證輸入
//根據 $this->defaultRuleAry 來驗證
return true;
}
public function save(array $options = array())