Skip to content

Instantly share code, notes, and snippets.

Avatar

Kerem Güneş k-gun

  • Istanbul, Turkey
View GitHub Profile
View parseQueryString.js
// Handles also array params well
function parseQueryString(query) {
var pars = (query != null ? query : "").replace(/&+/g, "&").split('&'),
par, key, val, re = /^([\w]+)\[(.*)\]/i, ra, ks, ki, i = 0,
params = {};
while ((par = pars.shift()) && (par = par.split('=', 2))) {
key = decodeURIComponent(par[0]);
// prevent param value going to be "undefined" as string
val = decodeURIComponent(par[1] || "").replace(/\+/g, " ");
View extract_path.php
function extract_array_path($path, $value = null, $base = null) {
if ($base === null) {
static $base = array();
}
$exp = explode('.', $path);
$tmp =& $base;
foreach($exp as $i) {
$tmp =& $tmp[$i];
}
@k-gun
k-gun / .htaccess
Last active Aug 29, 2015
Proper .htaccess configrations for subdir-based virtual server (Apache/2.4.7 (Ubuntu)).
View .htaccess
<VirtualHost *:80>
ServerName foo.com.local
DocumentRoot /var/www/foo.com/public
<Directory /var/www/foo.com/public>
Options +FollowSymLinks
DirectoryIndex index.php
AllowOverride all
Require all granted
View bbcode_convert.php
$str = <<<EOT
Lorem [a href="#"]ipsum[/a] [hr color="red" /] dolor...
[style].foo{color:#fff}[/style]
EOT;
function bbcode_convert($content) {
// remove style|script
$content = preg_replace(
'~(\[(style|sctript)\s?.*\](.*)\[/(\\2)\]|\[(%s)\s?.*/\])~ims', '', $content);
@k-gun
k-gun / reduce_slashes.php
Last active Aug 29, 2015
Reduce duplicated slashes.
View reduce_slashes.php
<?php
$url = "https://foo.com//bar/////ii?a=1";
$url = preg_replace("~(?<!:)/+~", "/", $url);
print($url); # https://foo.com/bar/ii?a=1
View Class.js
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;
@k-gun
k-gun / sublime-stuff.md
Last active Aug 29, 2015
Sublime Stuff...
View sublime-stuff.md
@k-gun
k-gun / git-memo
Last active Aug 29, 2015
Git memo
View git-memo
# delete a remote tag
git tag -d theTagName
git push origin :refs/tags/theTagName
@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);
@k-gun
k-gun / formatString.js
Last active Aug 29, 2015
Simple string formatter.
View formatString.js
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;
}
You can’t perform that action at this time.