Skip to content

Instantly share code, notes, and snippets.

View stojg's full-sized avatar

Stig Lindqvist stojg

View GitHub Profile
@stojg
stojg / ss-upgrade.sh
Created August 14, 2012 22:16
Search and replace for SS 3.0 upgrade [beta]
function replace {
echo Replacing '"'$1'"' with '"'$2'"'
find . \( -path './framework' -o -path './cms' -o -path './.git' \) -prune -o -name '*.php' -exec grep -l "$1" {} \; | xargs sed -i "" 's/'"$1"'/'"$2"'/g'
}
replace 'Director::currentPage(' 'Director::get_current_page('
replace 'Member::currentMember(' 'Member::currentUser('
replace 'new DataObjectSet' 'new ArrayList'
@stojg
stojg / go-scraper.go
Last active October 11, 2015 23:28
go implementation of a page scraper
/**
*
* Requires these 'thirdparty' packages
* go get github.com/moovweb/gokogiri
*/
package main
import (
"fmt"
"github.com/moovweb/gokogiri"
@stojg
stojg / go-bubble.go
Last active October 12, 2015 01:37
go implementation of bubble sort
package main
import "fmt"
func main() {
list := []int{1, 8, 10, 23, 3, -1, 2, 2, 6, 3, 4}
fmt.Println(list)
bubbleSort(list)
fmt.Println(list)
}
@stojg
stojg / ORM.php
Created November 2, 2012 03:04
ORM scratch board
<?php
/*
Ideas on ORM interface and interactions / relationships
*/
class Dataobject {
function __construct(Data $mapper, array $data = null) {
$this->mapper = $mapper;
if($data) {
@stojg
stojg / ss-upgrade.sh
Created November 8, 2012 00:21 — forked from phptek/ss-upgrade.sh
Search and replace for SS 3.0 upgrade [beta]
#!/bin/bash
#
# ss-upgrader.sh
#
# INTRODUCTION
#
# There are some threads on the SS forums that describe the techdocs for upgrading a 2.4 site to 3.x as being too technical. Mainly from content authors who
# also happen to be site maintainers - they are not coders.
# The aim of this script is to therefore to automate - in as much as this is possible in a user-configured, open-source software project - to help those new to
# SS3 upgrade from 2.x as smoothly as possible.
@stojg
stojg / CustomHierarchy.php
Last active October 13, 2015 08:17
SilverStripe Hierarchy replacement - Do not traverse into grandchildren in trees.
<?php
/**
* CustomHierarchy
*
* This hierarchy overrides the getChildrenAsUL to not cascade into every child, this makes the sitetree loading a bit
* snappier
*/
class CustomHierarchy extends Hierarchy {
/**
@stojg
stojg / ftp.php
Last active December 10, 2015 19:18
Quick recipe on how to the latest .zip file from a ftp server
<?php
$ftpConnection = array(
'host' => 'server.co.nz',
'username' => 'username',
'password' => 'secret-password'
);
// set up basic connection
$connection = ftp_connect($ftpConnection['host']);
<?php
$host = 'ldap://localhost';
$username = 'DOMAIN\\username';
$password = 'password';
$dn = "OU=Users,DC=company,DC=co,DC=nz";
if(!$argv[1]) {
$searchFilter = '(employeeID=*)';
} else {
$searchFilter = '(employeeID='.$argv[1].')';
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NGMCAw
IDAAEAGAAtIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVj
dF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FITltiaWttcn2GjpGa
@stojg
stojg / poetry.php
Last active December 11, 2015 20:59
<?php
$sorrows = array();
for($days=1;$idx<$days;$days++) { $sorrows[$days] = 'joy' };
foreach($sorrows as $feelings) {
echo mktime(10, 42, 0, 1, 29, 2012).' '.$feelings.PHP_EOL;
}