Skip to content

Instantly share code, notes, and snippets.

<!-- Old Github.tmTheme -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
======================================================================
Github
======================================================================
A Sublime Text 2 / Textmate theme.
Copyright (c) 2012 Dayle Rees.
Released under the MIT License <http://opensource.org/licenses/MIT>
<!-- SQL.tmLanguage -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>sql</string>
<string>ddl</string>
<string>dml</string>
@krmgns
krmgns / go.go
Last active November 16, 2015 00:54
Go tools.
import "fmt"
func Type(args ...interface{}) string {
return fmt.Sprintf("%T", args[0])
}
func Dump(args ...interface{}) {
fmt.Println(args...)
}
@krmgns
krmgns / readme.md
Created November 13, 2015 22:32 — forked from coolaj86/how-to-publish-to-npm.md
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 init.author.name "Your Name"
npm set init.author.email "[email protected]"
npm set init.author.url "http://yourblog.com"

npm adduser

@krmgns
krmgns / type-hint.php
Last active November 3, 2015 00:13
Spoofing PHP for default values with type-hint in functions/methods.
<?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);
@krmgns
krmgns / normalizePostFiles.php
Last active August 29, 2015 14:19
Normalize $_FILES returning assoc array.
<?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]
)) {
@krmgns
krmgns / laravel issues
Last active August 29, 2015 14:18
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
@krmgns
krmgns / arguments.php
Created March 30, 2015 15:23
Argument extracting with PHP (shorcut).
<?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 = [];
@krmgns
krmgns / type-hint.php
Last active November 2, 2015 23:44
Simulate PHP (hacked) type hint performance.
<?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)) {
@krmgns
krmgns / formatString.js
Last active August 29, 2015 14:15
Simple string formatter.
function formatString() {
var args = arguments, s = args[0], ms = s.match(/(%s)/g) || [], i = 1, m;
while (m = ms.shift()) {
s = s.replace(/(%s)/, args[i++]);
}
return s;
}