Skip to content

Instantly share code, notes, and snippets.

@vlakoff
vlakoff / lazy-typer.md
Last active October 25, 2017 12:54
Composer candy

Tired of typing composer selfupdate, composer install... ?
Good news, I just noticed you can omit most of the characters, it works as well.

You can cut down up to composer sel, composer ins...

Time saved, equals money, PROFIT! One more step to WORLD DOMINATION.

@vlakoff
vlakoff / relative-size.js
Created June 28, 2015 23:12
Increase or decrease CSS values thanks to jQuery
/*
cleaner than hard-coding the desired font size
refs: http://api.jquery.com/css/
some use case:
all these websites that use *huge* font sizes,
painful to read even on a 1920x1080 screen.
*/
$('.article-content').css('font-size', '-=2');
@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=/';
};
@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 / 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 / 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 / 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 - 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 / 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 / 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);