Skip to content

Instantly share code, notes, and snippets.

Avatar

Kerem Güneş k-gun

View GitHub Profile
@k-gun
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{}) {
fmt.Println(args...)
}
@k-gun
k-gun / readme.md
Created Nov 13, 2015 — forked from coolaj86/how-to-publish-to-npm.md
How to publish packages to NPM
View readme.md

Getting Started with NPM (as a developer)

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

npm set init.author.name "Your Name"
npm set init.author.email "you@example.com"
npm set init.author.url "http://yourblog.com"

npm adduser
@k-gun
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>html</string>
<string>htm</string>
<string>shtml</string>
<string>xhtml</string>
@k-gun
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
<?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
<?php
// what the fuck? :)
define('None', '');
define('True', true);
@k-gun
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
<?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
k-gun / type-hint.php
Last active Nov 2, 2015
Simulate PHP (hacked) type hint performance.
View type-hint.php
<?php
set_error_handler(function($ecode, $emesg, $efile, $eline) {
if (!$ecode || (error_reporting() & $ecode) == 0) {
return;
}
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
k-gun / normalizePostFiles.php
Last active Aug 29, 2015
Normalize $_FILES returning assoc array.
View normalizePostFiles.php
<?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],
$postFiles['tmp_name'][$i]
)) {
@k-gun
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/foo.com/app/storage/logs/.
if yet does not work, create file manually that that guy trying to write
like log-apache2handler-2015-04-03.txt
@k-gun
k-gun / arguments.php
Created Mar 30, 2015
Argument extracting with PHP (shorcut).
View arguments.php
<?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
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.