Skip to content

Instantly share code, notes, and snippets.

View stojg's full-sized avatar

Stig Lindqvist stojg

View GitHub Profile
@stojg
stojg / .gitconfig
Created August 30, 2011 08:48
.gitconfig
[alias]
pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
graph = log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short
co = checkout
st = status
ci = commit
br = branch
unstage = reset HEAD --
last = log -1 HEAD
[core]
@stojg
stojg / session.php
Last active September 27, 2015 13:57
How to set a custom session id on a SilverStripe site
<?php
session_destroy();
// Start a new session with the token from the url, this will reinitialize the _SESSION
Session::start('wished-session-id');
// Set the current session connected to the controller with an new instance with the proper _SESSION data
$session = new Session(isset($_SESSION) ? $_SESSION : null);
Controller::curr()->setSession($session);
// Some test that this actually works
@stojg
stojg / puppet-install.sh
Created November 10, 2011 19:06
Ubuntu puppet installation
#!/bin/bash
sudo apt-get update
sudo apt-get install irb libopenssl-ruby libreadline-ruby rdoc ri ruby ruby-dev
cd /usr/local/src
sudo wget http://production.cf.rubygems.org/rubygems/rubygems-1.5.2.tgz
sudo tar -xzf rubygems-1.5.2.tgz
cd rubygems-1.5.2
sudo ruby setup.rb
sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 1
sudo gem update --system
@stojg
stojg / install-puppet.sh
Created November 21, 2011 07:04
install puppet
#!/bin/bash
# cd /tmp/ && wget https://raw.github.com/gist/1381894/install-puppet.sh && bash ./install-puppet.sh
sudo apt-get install libopenssl-ruby rdoc libopenssl-ruby1.8 libreadline-ruby1.8 libruby1.8 rdoc1.8 ruby1.8
cd /tmp/
wget http://downloads.puppetlabs.com/facter/facter-1.5.7.tar.gz
tar xvzf facter-1.5.7.tar.gz
cd facter-1.5.7
sudo ruby install.rb
cd ..
rm -rf facter*
@stojg
stojg / deploy.rb
Last active September 30, 2015 00:08
Capistrano recipe for SS
# This is an example of how I use capistrano in a sweet symphony to deploy a SilverStripe site.
#
# If you haven't installed capistrano yet, now would be a good time to do it.
#
# sudo gem install capistrano
#
# Have a look at http://cheat.errtheblog.com/s/capistrano/ for some tricks.
# Otherwise http://theadmin.org/articles/capistrano-variables/ shows most vars
# And here is the original deploy.rb https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy.rb
@stojg
stojg / git-alias.sh
Created February 15, 2012 21:41
Some common git aliases
#/bin/bash
git config --global alias.ls "log --pretty=format:'%Cred%h%Creset %C(yellow)%ci%Creset %s - %C(bold blue)%an%Creset'"
@stojg
stojg / async-social-load.js
Last active October 3, 2015 06:48
Async loading of social jS with callbacks
(function(d, s) {
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id, callback) {
if (d.getElementById(id)) {return;}
js = d.createElement(s);js.src = url;js.id = id;js.async=true;
fjs.parentNode.insertBefore(js,fjs);
if(callback!=undefined) {
js.onload=callback;
//Extra for internet explorer
js.onreadystatechange = function () { if(this.readyState == 'complete' || this.readyState == 'loaded') { callback(); } }
}
@stojg
stojg / ContentAwareImage.php
Created April 23, 2012 05:06
Testing content aware cropping for SilverStripe Idea is that the automatic cropping will crop the most interesting part of the image
<?php
/**
* ContentAwareImage
*
* @author stig
*/
class ContentAwareImage {
protected static $start_time = 0.0;
@stojg
stojg / remove-tmp-db.php
Created June 13, 2012 00:22
Remove SilverStripe test databases
<?php
/**
* This script will drop all the databases that contains this string 'tmpdb'.
* Those databases are likely to be left over from a SilverStripe test run
* Usage: Make sure you change the db connection string below and run the
* script like:
* php remove-tmp-db.php
*/
// Change this to your db connection
@stojg
stojg / parse-xml.php
Last active November 18, 2022 21:31
Parsing a huge XML with closure in PHP
<?php
// An example on how to parse massive XML files with PHP by chunking it up to avoid running out of memory
// Open the XML
$handle = fopen('file.xml', 'r');
// Get the nodestring incrementally from the xml file by defining a callback
// In this case using a anon function.
nodeStringFromXMLFile($handle, '<item>', '</item>', function($nodeText){
// Transform the XMLString into an array and