Skip to content

Instantly share code, notes, and snippets.

View tureki's full-sized avatar
🐢
(╯°□°)╯︵ ┻━┻

Kah Wai Liew tureki

🐢
(╯°□°)╯︵ ┻━┻
View GitHub Profile
@tureki
tureki / BaseModel.php
Last active July 28, 2017 13:20
laravel-pgsql-n-related-models-per-parent
<?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 March 31, 2021 18:53
json_encode null to empty string.
$value = array(
"deep"=>1,
"data"=>null,
"node"=>array(
"deep"=>2,
"data"=>null,
"node"=>array(
"deep"=>3
)
),
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 December 17, 2014 14:51
iOS validate email format
-(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 August 11, 2014 13:05
Centos6.5 docker install
#!/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 July 30, 2014 02:00
hhvm centos6.5 fastcgi init
#!/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 August 29, 2015 14:00
Nginx's Log to Elasticsearch
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 May 24, 2023 19:27
Rsync when file changes on Mac
#!/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 March 18, 2014 11:30
Linux mysql backup shell script
#!/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 March 18, 2014 11:27
Linux postgresql backup shell script
#!/bin/bash
export PGCLIENTENCODING="UTF8"
DBLIST="$@"
if [ -z "${DBLIST}" ]; then
DBLIST="citytalk"
fi
#backup directory
BACKUP=/var/backup/database/pgsql/