Skip to content

Instantly share code, notes, and snippets.

View hungneox's full-sized avatar
✌️

Hung Neo hungneox

✌️
View GitHub Profile
<?php
$list = array(
array('id'=>1,'name'=>'Fashion','parent_id'=>null),
array('id'=>2,'name'=>'Men','parent_id'=>1),
array('id'=>3,'name'=>'Women','parent_id'=>1),
array('id'=>4,'name'=>'Jacket Men','parent_id'=>2),
array('id'=>5,'name'=>'Jacket Women','parent_id'=>3),
array('id'=>6,'name'=>'Bag','parent_id'=>null),
array('id'=>7,'name'=>'Bag Men','parent_id'=>6),
@hungneox
hungneox / combine_key_value.php
Last active December 20, 2015 10:39
combine key value with array_walk
<?php
$a = array(
'email' => 'test@test.com',
'desc' => 'Who know',
'button_link' => 'yest'
);
function qh_combine(&$item, $key){
$item = "$key : $item";
}
@hungneox
hungneox / knapsack01.php
Last active December 28, 2015 14:39
Knapsack 0/1
<?php
echo "PHP Knapsack 1/0 problem \n";
class Item
{
private $_weight;
private $_value;
public function __construct($value, $weight)
<?php
$data = array();
$data = array(
'channel' => 1,
'data' => array (
array(
'identity' => array('email' => 'email'),
'events' => array(
value = [[0 for x in xrange(0, W+1)] for x in xrange(0, n+1)]
keep = [[0 for x in xrange(0,W+1)] for x in xrange(0, n+1)]
for w in range(0, n):
value[0][w] = 0
keep[0][w] = 0
for i in xrange(1, n+1):
for w in xrange(0, W+1):
if((weight[i] <= w) and (v[i] + value[i-1][w-weight[i]] > value[i-1][w])):
<?php
$arr1 = array(0=>'0', 1=>'0', 2=>'0', 3=>'0', 4=>'0', 5=>'0', 6=>'0');
$arr2 = array(0=>'2', 3=>'5', 5=>'8');
$arr3 = array();
foreach($arr1 as $k1 => $v1){
foreach ($arr2 as $k2 => $v2) {
if($k1==$k2){
$arr3[$k1] = $v2;
@hungneox
hungneox / php_datetime.php
Last active August 29, 2015 13:58
Python datetime vs PHP DateTime
<?php
#Equivalent to this PHP codes:
$gmt_timezone = new DateTimeZone('GMT');
$obj_date = new DateTime(null,$gmt_timezone);
echo $obj_date->format('d/m/Y h:i:s');
#OR
date_default_timezone_set("GMT");
echo date('d/m/Y h:i:s', time());
?>
@hungneox
hungneox / php_string.php
Last active August 29, 2015 13:58
Python string function vs PHP string function
<?php
$parrot = "Norwegian Blue";
echo strlen($parrot);
echo strtolower($parrot);
echo strtoupper($parrot);
$pi = 3.14
echo $pi;
if(is_string($pi)):
@hungneox
hungneox / loops.rb
Last active August 29, 2015 13:58
Loops in Ruby
for num in 1..10
puts num
end
for i in 1..50
print i
end
i = 1
while i <= 50 do
@hungneox
hungneox / redacted.rb
Created April 6, 2014 02:45
Ruby simple program, modify original text, replace selected word with REDACTED
puts "Please input original text:"
text = gets.chomp
puts "Please input redact:"
redact = gets.chomp
words = text.split(" ")
words.each do |word|
if word == redact
print "REDACTED "