Skip to content

Instantly share code, notes, and snippets.


Kerem Güneş k-gun

View GitHub Profile
k-gun / go.go
Last active Nov 16, 2015
Go tools.
View go.go
import "fmt"
func Type(args ...interface{}) string {
return fmt.Sprintf("%T", args[0])
func Dump(args ...interface{}) {
k-gun /
Created Nov 13, 2015 — forked from coolaj86/
How to publish packages to NPM

Getting Started with NPM (as a developer)

If you haven't already set your NPM author info, now you should:

npm set "Your Name"
npm set ""
npm set ""

npm adduser
k-gun / HTML.tmLanguage
Last active Nov 12, 2015
Sublime theme
View HTML.tmLanguage
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
k-gun / type-hint.php
Last active Nov 3, 2015
Spoofing PHP for default values with type-hint in functions/methods.
View type-hint.php
function foo(bool $x = true) { var_dump($x); }
Fatal error: Default value for parameters with a class type hint can only be NULL in /var/www/... on line 2
// what the fuck? :)
define('None', '');
define('True', true);
k-gun / structure-stuff.php
Last active Nov 3, 2015
funny things with php structure stuff.. not kidding and i love php, use it if you like cos you are not bounded! :)
View structure-stuff.php
class PHP {
public function __call($method, $arguments) {
if (!method_exists($this, $method)) {
$_method = '_'. $method;
if (method_exists($this, $_method)) {
return call_user_func_array([$this, $_method], $arguments);
throw new Exception("No method such as '{$method}'!");
k-gun / type-hint.php
Last active Nov 2, 2015
Simulate PHP (hacked) type hint performance.
View type-hint.php
set_error_handler(function($ecode, $emesg, $efile, $eline) {
if (!$ecode || (error_reporting() & $ecode) == 0) {
if ($ecode == E_RECOVERABLE_ERROR) {
$pattern = '~^Argument (\d)+ passed to (.+) must be '.
'(?<type>of the type|an instance of) (?<hint>.+), (?<given>.+) given~i';
if (preg_match($pattern, $emesg, $match)) {
k-gun / normalizePostFiles.php
Last active Aug 29, 2015
Normalize $_FILES returning assoc array.
View normalizePostFiles.php
function normalizePostFiles(array $postFiles) {
$files = [];
if (isset($postFiles['tmp_name']) && is_array($postFiles['tmp_name'])) {
foreach ($postFiles['tmp_name'] as $i => $file) {
if (isset(
$postFiles['name'][$i], $postFiles['type'][$i],
$postFiles['size'][$i], $postFiles['error'][$i],
)) {
k-gun / laravel issues
Last active Aug 29, 2015
laravel issues
View laravel issues
if using apache, remove this line in .htaccess if POST'ing to an url
like /foo/. it is redirecting first to /foo and cancelling form submit.
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
ensure all dir's are writable like /var/www/
if yet does not work, create file manually that that guy trying to write
like log-apache2handler-2015-04-03.txt
k-gun / arguments.php
Created Mar 30, 2015
Argument extracting with PHP (shorcut).
View arguments.php
function arguments($limit = null) {
$callee =@ debug_backtrace(null, 2)[1];
if (empty($callee)) {
throw new \Exception(sprintf(
'Could not find callee in %s() funtion!', __function__));
$return = [];
k-gun / String.format.js
Created Feb 18, 2015
Simple string formatter with integer and float operators.
View String.format.js
String.prototype.format = function() {
var string = this.toString();
if (arguments.length) {
var tokens = string.match(/%([sdf])/g) || [],
token, i = 0, replace;
while (token = tokens.shift()) {
replace = arguments[i++];
switch (token) {
case "%d":
string = string.replace(token, parseInt(replace, 10) || 0);
You can’t perform that action at this time.