Skip to content

Instantly share code, notes, and snippets.

View ken-master's full-sized avatar

Ken ken-master

View GitHub Profile
@ken-master
ken-master / Strategy pattern
Last active August 29, 2015 14:23
PHP Strategy Pattern example
<?Php
/**
* Create the INTERFACE
**/
interface CharacterInterface{
public function attack();
public function dodge();
public function heal();
@ken-master
ken-master / strategy2
Created June 27, 2015 07:32
PHP Strategy Pattern Example 2
<?php
interface AnimalInterface{
public function run();
}
class Dog implements AnimalInterface{
public function run()
{
@ken-master
ken-master / ajax.js
Last active August 29, 2015 14:26
PHP: Cross Domain Allow Origin with Jquery AJAX
$.ajax({
url: '/ajax/url.php',
type:'POST',
data: data,
crossDomain: true, //essentials
xhrFields:{withCredentials:true}, //essentials
success: function(data) {
console.log(data);
}
});
@ken-master
ken-master / bash.sh
Created August 20, 2015 07:15
Linux Mount SSHFS follow symlinks
sshfs -o -follow_symlinks username@server_or_ip:/path/to/remote/folder/ /path/to/local/mount/folder
@ken-master
ken-master / route_traverse.php
Created November 7, 2015 00:19
[laravel] Traversing route name
<?php
$array = array(
'index.index','index.create','index.update','index.delete','role.index','role.create','role.update','role.delete'
);
$route_name = array('index','role');
@ken-master
ken-master / Staircase.php
Last active August 5, 2016 01:19
Staircase Hash
<?php
$n = 50;
$hash = str_repeat("#",$n);
for($x = $n;$x>=0;$x--){
$test = preg_replace("/\#/"," ",$hash,$x);
if( !ctype_space($test) ){
echo $test."\n";
}
@ken-master
ken-master / diagonal_array_summation.php
Created February 12, 2016 07:27
diagonal array summation
<?php
$handle = fopen ("php://stdin","r");
fscanf($handle,"%d",$n);
$a = array();
for($a_i = 0; $a_i < $n; $a_i++) {
$a_temp = fgets($handle);
$a[] = explode(" ",$a_temp);
array_walk($a[$a_i],'intval');
}
@ken-master
ken-master / tictactoe.html
Last active February 15, 2016 14:51
Tic Tac Toe using javascript (jquery)
<!DOCTYPE html>
<html>
<head>
<style>
tr > td {
height: 30px;
width:30px;
align: center;
@ken-master
ken-master / peak.php
Created February 23, 2016 14:34
Peak
<?php
function solution($A) {
$i = 0;
$k = 0;
$arr_count = count($A);
for( $j = 0;$j<=$arr_count;$j++ ){
$k = $A[$i];
@ken-master
ken-master / fuzzbuzzwoof.php
Created February 23, 2016 14:35
Fuzz,Buzz & Woof
<?php
function solution($N) {
//asuming $N is a range of numbers integr
for ($i = 1; $i <= $N; $i++){
if( $i%3 == 0 && $i%5 == 0 && $i%7 == 0 ){
echo "FizzBuzzWoof\n";
}elseif( $i%3 == 0 && $i%5 == 0){
echo "FizzBuzz\n";
}elseif($i%3 == 0 && $i%7 == 0){