Skip to content

Instantly share code, notes, and snippets.

/*
highlight v3 !! Modified by Jon Raasch (http://jonraasch.com) to fix IE6 bug !!
Highlights arbitrary terms.
<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>
MIT license.
@vlakoff
vlakoff / jquery.cookie.js
Created July 5, 2012 03:01 — forked from mathiasbynens/jquery.cookie.js
Improved jQuery.cookie plugin
@vlakoff
vlakoff / whitespace-benchmark.php
Last active October 10, 2015 21:58
Optimizing character_limiter() of CodeIgniter's text helper
// https://github.com/bcit-ci/CodeIgniter/pull/1750
$nb = 1000;
$str = str_repeat('<lorem ipsum here>' . "\n", 10);
$t1 = microtime(true);
for ($i = $nb; $i--; ) {
preg_replace('/\s+/', ' ', $str);
}
$t2 = microtime(true);
@vlakoff
vlakoff / compiled-dir-fix.php
Created July 31, 2013 04:47
Change the hardcoded paths in bootstrap/compiled.php to dynamic paths. Make the compiled Laravel application really portable.
<?php
file_exists('./bootstrap/compiled.php') || exit('File compiled.php not found');
$content = file_get_contents('./bootstrap/compiled.php');
$root = realpath('.');
// foo\bar --> foo/bar
@vlakoff
vlakoff / Stringy - charsArray.php
Created January 13, 2015 15:16
Stringy - Get and manipulate $charsArray at runtime
<?php
require './vendor/autoload.php';
use Stringy\Stringy;
class MyStringy extends Stringy {
public $managedCharsArray;
@vlakoff
vlakoff / Stringy - extend from instance.php
Created January 13, 2015 15:18
Stringy - Create extended Stringy from existing instance
<?php
require './vendor/autoload.php';
use Stringy\Stringy;
class MyStringy extends Stringy {
// http://php.net/manual/en/language.oop5.visibility.php#language.oop5.visibility-other-objects
@vlakoff
vlakoff / Stringy - quick check.php
Created January 16, 2015 23:59
Stringy - Quick check for proposed changes in $charsArray
<?php
require './vendor/autoload.php';
use Patchwork\Utf8;
use Stringy\Stringy;
class MyStringy extends Stringy {
public function charsArray() {
@vlakoff
vlakoff / phpdump.cmd
Last active September 13, 2015 14:17
A batch file for quickly dumping PHP expressions
@SETLOCAL
@SET expr=%*
@SET expr=%expr:"=\"%
@IF ^%expr:~-1%==^; SET expr=%expr:~0,-1%
@php -r "var_dump(%expr%);"
::A few examples:
::phpdump PHP_OS // "Everything should be made as simple as possible, but not simpler."
::phpdump ord("\n") // double quotation marks don't produce errors
::phpdump hexdec('ff'); // trailing semicolon should be omitted, yet it is supported for convenience
@vlakoff
vlakoff / HideConsole.vbs
Created May 11, 2015 07:51
Call a Windows batch file without showing the console window
' taken from FreeFileSync - www.freefilesync.org
set argIn = WScript.Arguments
num = argIn.Count
if num = 0 then
WScript.Echo "Call a Windows batch file (*.cmd, *.bat) without showing the console window" & VbCrLf & VbCrLf &_
"Command line:" & VbCrLf & "WScript HideConsole.vbs MyBatchfile.cmd <command line arguments>"
WScript.Quit 1
end if
@vlakoff
vlakoff / cookies.js
Created June 26, 2015 03:56
Simple, no-dependency JavaScript to set and delete cookies
function setCookie(name, value, days) {
var t = new Date();
t.setDate(t.getDate() + days);
document.cookie = encodeURIComponent(name)+'='+encodeURIComponent(value)+'; expires='+t.toUTCString()+'; path=/';
}
function deleteCookie(name) {
// value is an empty string
document.cookie = encodeURIComponent(name)+'=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
};