Skip to content

Instantly share code, notes, and snippets.

Simon Ljungberg simme

Block or report user

Report or block simme

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 grep.php
* Search a block of text for a given text string
* @param string $pattern
* A regexp to match against
* @param string|array $input
* A string or array (can't handle recursiveness) to search
* @param int $context
* Returns x number of lines surrounding the hit
View Swedish node-sorting.php
* Make MySQL correctly sort nodes on swedish sites
function hook_install() {
db_query("ALTER TABLE {node} MODIFY
title VARCHAR(255)
COLLATE utf8_swedish_ci");
View kill_the_bastard.php
// One liner to kill the bastards.
preg_replace('/\s(?!.*\s)/', '&nbsp;', $string);
View char_counter_deluxe.js
// Character counter
$('#edit-field-tagline-0-value, #edit-body').keydown(function(event) {
var id = $(this).attr('id');
var counter = $('label[for="' + id + '"]').children('span');
if (!counter.length) {
$('label[for="' + id + '"]').append('<span></span>');
counter = $('label[for="' + id + '"]').children('span');
counter.text(' (Antal tecken: ' + $(this).val().length + ')');
simme / Find Mate
Created Oct 25, 2010
Small bash function for opening a set of files in mate based on a search pattern
View Find Mate
#!/usr/bin/env bash
# Usage: fm nameoffile.php
# Searches the current dir you're in
function fm {
find . -name "$1" -exec mate {} \;
View Deploy backuped sites.php
* @file
* Deploy site backups as new sites on a new server.
* Duplicate platform before doing this.
// Path to directory containing backups
define('BACKUP_PATH', '/var/aegir/backups');
simme / ChangeLanguage.js
Created Nov 24, 2010
Client side language switching
View ChangeLanguage.js
var language = (function ($) {
var current = 'en'
, languages = { sv: {}
, da: {}
, en: {}
, self = {};
* Set the language strings
simme / Base64Image.php
Created Dec 30, 2010
Returns the Base64 encoded version of an image. Has basic support for Drupal module ImageCache. Does not depend on Drupal.
View Base64Image.php
* @file
* Helper class for encoding images as Base64.
* Has support for the Drupal module ImageCache, just provide it with your
* preset name if you'd like the class to use that version of an image instead.
* Is by no means dependent on Drupal though. Just a nice feature.
* Feel free to use it as you like.
* @author Simon Ljungberg <>
simme / drupal_language_update.php
Created Apr 12, 2011
Update translations on a Drupal site
View drupal_language_update.php
// Update translations
// This might need some 'splainin':
// RecursiveDirectoryIterator together with RecursiveIteratorIterator
// loops through all files in the give root directory.
// RegexIterator filters out the files we want (modules-topbar and
// themes-xskane) translations in this case. Matches the languages code
// and filename. Then we loop through it and win.
$di = new RecursiveDirectoryIterator('./sites/all/translations/');
$it = new RecursiveIteratorIterator($di);
simme / HTMLWeld.js
Created Apr 13, 2011
Welds data with HTML
View HTMLWeld.js
* @file
* Generates some various HTML stuffs.
var fs = require('fs')
, jsdom = require('jsdom')
* Welds some HTML together with a bunch of data
You can’t perform that action at this time.