Skip to content

Instantly share code, notes, and snippets.

View gaqzi's full-sized avatar

Björn Andersson gaqzi

View GitHub Profile
# ruby 1.8.7
# Hash implicitly creates an array for empty nodes
a = Hash.new([])
a[:key] << 2 # => [2]
p a # => {} nil
p a[:key] # => [2]
# Explicitly add an array for all nodes before creating
b = Hash.new
#!/bin/bash
# requires bash 3
URL=http://piratepad.net/ep/admin/auth
EXPECTED_CODE=200
TEST_FILE=/tmp/pad-watcher
TIMEOUT=300 # 5 minutes
RESTART_COMMAND='/opt/piratepad/bin/restart.sh &'
LAST_UPDATED_JS='/opt/piratepad/etherpad/data/50x-error-handler/last-updated.js'
CREATE TABLE IF NOT EXISTS `node_convert` (
`nid` int(11) NOT NULL,
`created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL,
`lang` varchar(5) character set utf8 NOT NULL,
`title` varchar(255) character set utf8 NOT NULL,
`url` varchar(255) character set utf8 NOT NULL,
`body` longtext character set utf8 NOT NULL,
`teaser` text character set utf8 NOT NULL,
`new_nid` int(11) NOT NULL,
module ImageHelper
def image(name, alt, link = '')
tmp = File.join(Dir.getwd, 'content')
possible_paths = [
File.join(tmp, @page.directory, 'images', name),
File.join(tmp, 'images', name)
]
file = possible_paths.find {|path| File.exists? path }
file
#!/bin/bash
# Author: Björn Andersson <bjorn.andersson@piratpartiet.se>
#
# Piratpartiet has two servers running Varnish and keeping them both in sync
# started to get cumbersome. A quick search on Google gave nothing so I wrote
# this script to ease the maintenance of activating new configuration files on
# a Varnish farm.
#
# How the script works:
# - The directory holding the varnish configuration will be synced to all
@gaqzi
gaqzi / nan.patch
Created April 18, 2011 08:38
Ruby Spreadsheet, NaN is a Float but it doesn't adhere to any operations so doing multiplication on a NaN will make the script explode
--- orig/worksheet.rb 2011-04-18 10:26:50.000000000 +0200
+++ patched/worksheet.rb 2011-04-18 10:27:23.000000000 +0200
@@ -89,7 +89,7 @@
def need_number? cell
if cell.is_a?(Numeric) && cell.abs > 0x1fffffff
true
- elsif cell.is_a?(Float)
+ elsif cell.is_a?(Float) and not cell.nan?
higher = cell * 100
if higher == higher.to_i
@gaqzi
gaqzi / README
Created June 1, 2011 16:42
Installation patch for Citrix Receiver v11.100 when installing manually
If you have "too much" free space the installation stops because the resulting
SPACE_AVAILABLE is not just numbers, and thus can't be used by expr.
This patch removes all characters that is not numeric, so in my case the
free space changes from 210974368K to 210974368 and I can install the receiver.
Running on Ubuntu 11.04 with the tools installed for that version.
*.rb diff=ruby
class Migration(DataMigration):
def forwards(self, orm):
if settings.DEBUG:
app, _ = FacebookApplication.objects.get_or_create(
id=123456,
secret='sssh',
default_scope='user_likes,email'
)
# Yet another test page
page, _ = FacebookPage.objects.get_or_create(id=123456)
@gaqzi
gaqzi / upload-archive-to-phonegap-build.sh
Created September 4, 2013 17:29
Takes a zip/tar.gz and uploads it to PhoneGap build while showing a progress bar.
#!/bin/bash
TOKEN=phonegap-build-access-token
APP_ID=phonegap-build-app-id
PROGRESS_FILE=/tmp/$TOKEN-progress
echo "" > $PROGRESS_FILE
tail -f $PROGRESS_FILE &
curl -X PUT -F file=@$1 https://build.phonegap.com/api/v1/apps/$APP_ID?auth_token=$TOKEN -o /tmp/$TOKEN-progress --progress-bar
kill $!