Skip to content

Instantly share code, notes, and snippets.

Stig Lindqvist stojg

Block or report user

Report or block stojg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stojg
stojg / get_links.php
Created Nov 18, 2010
Get all links from a website page
View get_links.php
View php.sessionhandler.php
<?php
/**
* @package ClusteredSessionHandler
*
* This class replaces the default php session handler with one that is more
* suitable for clustered environment.
*
* It utilizes the database to save the session data and may also use memcache
* as a write-throu cache layer to speed up fetching of data
*
@stojg
stojg / Timer.php
Created Feb 1, 2011
PHP5 Utility timer for fast benchmarks of code
View Timer.php
<?php
class Timer {
protected static $start_time = 0.00;
protected static $total_time = 0.00;
public static function start() {
self::$start_time = microtime(true);
}
@stojg
stojg / SiteTreeOptimizationDecorator.php
Created Feb 12, 2011
An example on how to add indexes on silverstripe dataobjects
View SiteTreeOptimizationDecorator.php
<?php
class SiteTreeOptimizationDecorator extends DataObjectDecorator {
public function extraStatics() {
return array(
'indexes' => array(
// Will help when fetching menu's
'showinmenus_sort' => '(ShowInMenus,Sort)',
// Will help when fetching a page from sitetree
'urlsegment_sort' => '(URLSegment,Sort)',
)
@stojg
stojg / deploy.rb
Created Mar 12, 2011
Silverstripe + Capistrano + Git recipie
View deploy.rb
# My ./config directory in silverstripe looks like this:
# ./503.php <- a 503 Maintainance page
# ./_ss_environment.php <- the production environment settings
# ./deploy.rb <- is the recipe below
#
# Application settings
set :application, "domain.com"
set :shared_children, %w(assets)
@stojg
stojg / diskspace.sh
Last active Sep 12, 2018
Find sizes of folders in a with a bash oneliner
View diskspace.sh
#!/bin/sh
# Installation: curl -o diskspace.sh "https://gist.githubusercontent.com/stojg/867224/raw/diskspace.sh" && chmod +x diskspace.sh
du -xsk ./* | sort -n | awk 'BEGIN{ pref[1]="K"; pref[2]="M"; pref[3]="G";} { total = total + $1; x = $1; y = 1; while( x > 1024 ) { x = (x + 1023)/1024; y++; } printf("%g%s\t",int(x*10)/10,pref[y],$0); } { for (i=2; i<=NF; i++) printf "%s ", $i; printf "\n"; } END { y = 1; while( total > 1024 ) { total = (total + 1023)/1024; y++; } printf("Total: %g%s\n",int(total*10)/10,pref[y]); }'
@stojg
stojg / import-remote-db.sh
Created Mar 14, 2011
Dump a mysql database remotely and importing it locally.
View import-remote-db.sh
#!/bin/bash
SSH_SERVER=server.com
SSH_USER=user
REMOTE_DB_USER=remotedbuser
REMOTE_DB_PASSWORD=remotedbpassword
REMOTE_DB_SCHEMA=remotedbschema
LOCAL_DB_USER=localdbuser
LOCAL_DB_PASSWORD=localdbpassword
LOCAL_DB_SCHEMA=localdbschema
@stojg
stojg / webdev.sh
Created May 23, 2011
This little bashscripts start / stops my VM, mounts / unmounts a samba folder, starts my editor and ssh into the VM. Mac OS X.
View webdev.sh
#/bin/bash
SAMBAUSERNAME="stig"
SERVERNAME="172.16.155.x"
PASSWORD="sambapassword"
MOUNTPATH="/Volumes/$SAMBAUSERNAME"
VMFUSION="/Library/Application Support/VMware Fusion/vmrun"
VMPATH="/Users/stig/Documents/CentOS/CentOS.vmx"
EDITOR="/Applications/NetBeans/NetBeans 7.0.app"
start_vm() {
@stojg
stojg / email-stojg.sh
Last active Sep 26, 2015
Sending emails via your gmail account to my email
View email-stojg.sh
#/bash/bin
php -r 'function gp($a=false){$b=shell_exec("stty -g");if($a===false){shell_exec("stty -echo");$c=rtrim(fgets(STDIN),"\n");}else{shell_exec("stty -icanon -echo min 1 time 0");$c="";while(true){$d=fgetc(STDIN);if($d==="\n"){break;}else if(ord($d)===127){if(strlen($c)>0){fwrite(STDOUT,"\x08 \x08");$c=substr($c,0,-1);}}else{fwrite(STDOUT,"*");$c.=$d;}}}shell_exec("stty ".$b);return $c;}echo"Your gmail @: ";$ha=fopen("php://stdin","r");$f=trim(fgets($ha));echo"Your gmail pass: ";$p=gp(1);echo"\nWhat do you want(enters sends message): ";$m=trim(fgets($ha));function s($c,$m){fputs($c,$m."\r\n");}function r($c){return fgets($c,4096);}function e($m){return base64_encode($m);}function m($f,$p,$m){$r="g@stojg.net";$n="\r\n";$c=fsockopen("smtp.gmail.com",587,$z,$y,10);r($c);s($c,"HELO");r($c);s($c,"STARTTLS");r($c);stream_socket_enable_crypto($c,true,STREAM_CRYPTO_METHOD_TLS_CLIENT);s($c,"HELO");r($c);s($c,"AUTH LOGIN");r($c);s($c,e($f));r($c);s($c,e($p));r($c);s($c,"MAIL FROM: <$f>");r($c);s($c,"RCPT TO: <$r
@stojg
stojg / ChangeDecorator.php
Created Aug 23, 2011
Silverstripe visitor pattern
View ChangeDecorator.php
<?php
class ChangeDecorator extends DataObjectDecorator {
/**
*
*/
public function onAfterWrite() {
$publisher = PublisherQueueVisitor::instance();
$this->getOwner()->accept($publisher);
You can’t perform that action at this time.