Skip to content

Instantly share code, notes, and snippets.

View E1101's full-sized avatar
🏠
Working from home

Payam Naderi E1101

🏠
Working from home
View GitHub Profile
@E1101
E1101 / .gitignore
Last active August 29, 2015 14:01
gitignore
/.vagrant
.buildpath
.DS_Store
.idea
.project
.settings/
.*.sw*
.*.un~
build/
composer.lock
@E1101
E1101 / MetaTrait.php
Created May 24, 2014 10:28
Add methods on the fly to an object.
<?php
trait MetaTrait
{
private $methods = array();
public function addMethod($methodName, $methodCallable)
{
if (!is_callable($methodCallable)) {
throw new InvalidArgumentException('Second param must be callable');
@E1101
E1101 / unique-string.php
Last active August 29, 2015 14:05
Get unique string in length
<?php
function($length) {
$char = "abcdefghijklmnopqrstuvwxyz0123456789";
$char = str_shuffle($char);
for($i = 0, $rand = '', $l = strlen($char) - 1; $i < $length; $i ++) {
$rand .= $char{mt_rand(0, $l)};
}
return $rand;
};
@E1101
E1101 / sekeleton-appmodule.js
Last active August 29, 2015 14:06
js module skeleton
// initially you create your main application module that will
// load all his child modules
myapp = (function ($) {
'use strict';
var pub = {
initModule: function (module) {
if (module.isActive === undefined || module.isActive) {
if ($.isFunction(module.init)) {
module.init();
@E1101
E1101 / featured-mobile-detection.js
Last active August 29, 2015 14:07
Mobile Detection
@E1101
E1101 / ci_array_intersect.php
Created May 25, 2015 09:18
array_intersect case-insensitive and ignoring tildes
<?php
function to_lower_and_without_tildes($str,$encoding="UTF-8") {
$str = preg_replace('/&([^;])[^;]*;/',"$1",htmlentities(mb_strtolower($str,$encoding),null,$encoding));
return $str;
}
function compare_function($a,$b) {
return to_lower_and_without_tildes($a)===to_lower_and_without_tildes($b)?0:1;
}
@E1101
E1101 / inheritance-type-declarations.php
Created September 19, 2015 12:49
php inheritance interface type declarations
<?php
interface iInvokable {
function __invoke($arg = null);
}
interface iResponder extends iInvokable {
/** Bind next responder */
function then(iInvokable $responder);
}
@E1101
E1101 / encryption.php
Last active April 19, 2016 06:15
Encryption
<?php
class Crypto {
/**
* Encrypt using 3DES
*
* @param string $clear clear text input
* @param string $key encryption key to retrieve from the configuration, defaults to 'des_key'
* @param boolean $base64 whether or not to base64_encode() the result before returning
*
* @return string encrypted text
@E1101
E1101 / curl_client.php
Created July 26, 2017 11:05
Curl Http Client
<?php
class Client
{
public function get($url, array $options = [])
{
$options = array_merge([ 'method' => 'get', 'url' => $url ], $options);
return $this->request($options);
}
public function post($url, array $data = [], array $options = [])
@E1101
E1101 / parse_token.php
Created October 4, 2017 14:02
Parse Token From Request
<?php
/**
* As per the Bearer spec (draft 8, section 2) - there are three ways for a client
* to specify the bearer token, in order of preference: Authorization Header,
* POST and GET.
*
* @param ServerRequestInterface $request
*
* @return null|string Token
*/