Skip to content

Instantly share code, notes, and snippets.

View stojg's full-sized avatar

Stig Lindqvist stojg

View GitHub Profile
@stojg
stojg / get_links.php
Created November 18, 2010 07:29
Get all links from a website page
<?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 February 1, 2011 14:39
PHP5 Utility timer for fast benchmarks of code
<?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 February 12, 2011 09:02
An example on how to add indexes on silverstripe dataobjects
<?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 March 12, 2011 11:53
Silverstripe + Capistrano + Git recipie
# 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 June 8, 2022 22:32
Find sizes of folders in a with a bash oneliner
#!/bin/sh
# Installation: curl -o /usr/bin/diskspace.sh "https://gist.githubusercontent.com/stojg/867224/raw" && chmod +x /usr/bin/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 March 14, 2011 14:44
Dump a mysql database remotely and importing it locally.
#!/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 08:21
This little bashscripts start / stops my VM, mounts / unmounts a samba folder, starts my editor and ssh into the VM. Mac OS X.
#/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 September 26, 2015 13:48
Sending emails via your gmail account to my email
#/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="[email protected]";$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 August 23, 2011 11:17
Silverstripe visitor pattern
<?php
class ChangeDecorator extends DataObjectDecorator {
/**
*
*/
public function onAfterWrite() {
$publisher = PublisherQueueVisitor::instance();
$this->getOwner()->accept($publisher);