Skip to content

Instantly share code, notes, and snippets.

var Class = (function() {
return {
create: function(prototype){
function Class() {
if (this.init && this.init.apply) {
this.init.apply(this, arguments);
}
}
Class.prototype = prototype;
Class.prototype.constructor = Class;
@krmgns
krmgns / HTML.tmLanguage
Last active November 12, 2015 16:49
Sublime theme
<?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>
@krmgns
krmgns / sublime-stuff.md
Last active August 29, 2015 14:14
Sublime Stuff...
@krmgns
krmgns / git-memo
Last active August 29, 2015 14:15
Git memo
# delete a remote tag
git tag -d theTagName
git push origin :refs/tags/theTagName
@krmgns
krmgns / String.format.js
Created February 18, 2015 16:02
Simple string formatter with integer and float operators.
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);
@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;
}
@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 / 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 / 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 / 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]
)) {