Skip to content

Instantly share code, notes, and snippets.

View slav123's full-sized avatar

Slawomir Jasinski slav123

View GitHub Profile
@slav123
slav123 / filter.php
Created October 13, 2014 02:44
remove null or false from table
<?php
/**
I had an array with something like the following: Array ( [0] => [1] => test [2] => fun ). But I don't want [0], the empty value in the array.
After searching the web for a good solution, I saw that people were using anywhere from 4 to 10+ lines of code to remove null values from arrays. This is obviously overkill so I decided to tackle the problem myself.
Remove NULL values only
**/
$new_array_without_nulls = array_filter($array_with_nulls, 'strlen');
@slav123
slav123 / s3policy.json
Created November 12, 2014 05:32
s3 bucket policy for s3cmd sunc command
{
"Statement": [
{
"Action": [
"s3:ListAllMyBuckets"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::*"
},
{
@slav123
slav123 / pagespeed.conf
Created November 20, 2014 22:20
disable mode page speed
<IfModule pagespeed_module>
ModPagespeed off
</IfModule>
@slav123
slav123 / hhvm cli
Created December 2, 2014 06:59
hhvm command line
hhvm -vEval.Jit=1
@slav123
slav123 / PublicReadGetObject.json
Created December 8, 2014 22:40
s3 read public
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
@slav123
slav123 / rpn.php
Last active August 29, 2015 14:11
Reverse Polish Notation
<?php
// some tests to run
$tests[] = array(2, 1, '+', 3, '*');
$tests[] = array(4, 10, 5, '/', '+');
$tests[] = array(4, 13, 5, '/', '+');
$tests[] = array(4, 2, 5, '*', '+', 1, 3, 2, '*', '+', '/');
// expected resuluts
$expected = array(9, 6, 6.6, 2);
@slav123
slav123 / download.sh
Created February 4, 2015 04:31
curl get with headers and compression
curl -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/21.0" -H "Accept-Encoding: gzip, deflate" http://www.realestate.com.au/sold/in-nsw/list-2 --output "list-2"
@slav123
slav123 / get_pkey.php
Created February 10, 2015 04:51
return only given key from bigger array
<?php
/**
* capture only id from bigger array
*
* @param array $array input
* @param array $pkey primary key
*
* @return array
*/
function array_id($array, $pkey)
@slav123
slav123 / hlreporter.sh
Created February 19, 2015 22:12
hlreporter
#!/bin/bash
# hlreporter service controller script
cd "/root/hlreporter-1.0.10/"
case "$1" in
start)
./hlreporter multirun &
;;
stop)
@slav123
slav123 / md5.go
Created March 18, 2015 04:01
md5.go
import (
"crypto/md5"
"encoding/hex"
)
func GetMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}