Skip to content

Instantly share code, notes, and snippets.

🐢
(╯°□°)╯︵ ┻━┻

Kah Wai Liew tureki

🐢
(╯°□°)╯︵ ┻━┻
View GitHub Profile
@tureki
tureki / BaseModel.php
Last active Jul 28, 2017
laravel-pgsql-n-related-models-per-parent
View BaseModel.php
<?php
/**
* MYSQL Reference: http://softonsofa.com/tweaking-eloquent-relations-how-to-get-n-related-models-per-parent/
* PGSQL Reference: http://stackoverflow.com/questions/21154752/postgresql-limit-for-each-in-clause
*/
class BaseModel extends \Eloquent {
/**
* query scope nPerGroup
@tureki
tureki / json_encode-null-to-empty-string-1.php
Last active Nov 22, 2019
json_encode null to empty string.
View json_encode-null-to-empty-string-1.php
$value = array(
"deep"=>1,
"data"=>null,
"node"=>array(
"deep"=>2,
"data"=>null,
"node"=>array(
"deep"=>3
)
),
View gist:5de6be28c69ab7e9e5f9
NSSet *products = [NSSet setWithArray:@[@"PRODUCT"]];
[[RMStore defaultStore] requestProducts:products success:^(NSArray *products, NSArray *invalidProductIdentifiers) {
for (int i = 0; i < [products count]; ++i)
{
SKProduct *p = products[i];
NSLog(@"Product title: %@" , p.localizedTitle);
NSLog(@"Product description: %@" , p.localizedDescription);
NSLog(@"Product price: %@" , p.price);
@tureki
tureki / validate
Created Dec 17, 2014
iOS validate email format
View validate
-(BOOL) NSStringIsValidEmail:(NSString *)checkString
{
BOOL stricterFilter = NO; // Discussion http://blog.logichigh.com/2010/09/02/validating-an-e-mail-address/
NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}";
NSString *laxString = @".+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:checkString];
}
@tureki
tureki / docker.sh
Created Aug 11, 2014
Centos6.5 docker install
View docker.sh
#!/bin/bash
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y install docker-io
docker run centos /bin/echo "Hello World"
chkconfig docker on
service docker start
@tureki
tureki / hhvm
Created Jul 30, 2014
hhvm centos6.5 fastcgi init
View hhvm
#!/bin/bash
. /etc/rc.d/init.d/functions
test -x /usr/bin/hhvm || exit 0
case "$1" in
start)
#/usr/bin/hhvm --config /etc/hhvm/config.hdf --user apache --mode daemon
/usr/bin/hhvm --config /etc/hhvm/config.hdf --mode daemon -vServer.Type=fastcgi -vServer.Port=9000
@tureki
tureki / logstash.conf
Last active Aug 29, 2015
Nginx's Log to Elasticsearch
View logstash.conf
input {
file {
type => "nginx_access"
codec=>json
path => ["/var/log/nginx/**"]
exclude => ["*.gz", "error.*"]
discover_interval => 10
sincedb_path => "/opt/logstash/.sincedb"
}
}
@tureki
tureki / fswatch.sh
Last active Aug 29, 2015
Rsync when file changes on Mac
View fswatch.sh
#!/bin/bash
#install fswatch
brew install fswatch
#fswatch to keep a directory in sync with other directory
fswatch-run /Users/tureki/Desktop/files/ /Users/tureki/sh/rsync.sh
@tureki
tureki / mysql-backup.sh
Created Mar 18, 2014
Linux mysql backup shell script
View mysql-backup.sh
#!/bin/bash
export PGCLIENTENCODING="UTF8"
DBLIST="$@"
if [ -z "${DBLIST}" ]; then
DBLIST="all"
fi
#backup directory
BACKUP=/var/backup/database/mysql/
@tureki
tureki / postgres-backup.sh
Created Mar 18, 2014
Linux postgresql backup shell script
View postgres-backup.sh
#!/bin/bash
export PGCLIENTENCODING="UTF8"
DBLIST="$@"
if [ -z "${DBLIST}" ]; then
DBLIST="citytalk"
fi
#backup directory
BACKUP=/var/backup/database/pgsql/
You can’t perform that action at this time.