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
View .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 Sep 27, 2015
How to set a custom session id on a SilverStripe site
View session.php
<?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 Nov 10, 2011
Ubuntu puppet installation
View puppet-install.sh
#!/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
View install-puppet.sh
#!/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 Sep 30, 2015
Capistrano recipe for SS
View deploy.rb
# 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 Feb 15, 2012
Some common git aliases
View git-alias.sh
#/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 Oct 3, 2015
Async loading of social jS with callbacks
View async-social-load.js
(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 Apr 23, 2012
Testing content aware cropping for SilverStripe Idea is that the automatic cropping will crop the most interesting part of the image
View ContentAwareImage.php
<?php
/**
* ContentAwareImage
*
* @author stig
*/
class ContentAwareImage {
protected static $start_time = 0.0;
@stojg
stojg / remove-tmp-db.php
Created Jun 13, 2012
Remove SilverStripe test databases
View remove-tmp-db.php
<?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 Feb 11, 2019
Parsing a huge XML with closure in PHP
View parse-xml.php
<?php
// 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
print_r(getArrayFromXMLString($nodeText));
You can’t perform that action at this time.