Skip to content

Instantly share code, notes, and snippets.

@cimm
cimm / vpn-warning.sh
Created March 26, 2018 21:19
Intended to run in cron, a little nudge to warn me to turn on my VPN
#!/bin/sh
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";
if /sbin/ifconfig tun0; then
echo "VPN is active";
else
DISPLAY=:0 notify-send "VPN is not active"
fi
@cimm
cimm / AuthorDelegate.qml
Created March 27, 2015 09:02
Nested elements in a QML XmlListModel
import QtQuick 2.0
ListView {
property int parentIndex
height: 20
model: MyXmlListModel{
query: "/papers/paper["+parentIndex+"]/authors/author"
}
@cimm
cimm / image_width.js
Created February 2, 2015 19:48
Get the image width in client side JavaScript
var file = ... // a File web API interface: https://developer.mozilla.org/en-US/docs/Web/API/File
img = new Image();
img.src = URL.createObjectURL(file);
img.onload = function() {
alert(this.naturalWidth);
};
@cimm
cimm / localized_ruby.rb
Created November 23, 2012 15:50 — forked from jimeh/__readme.md
Let's not localize programming languages. Please >_<
# Let's not localize programming languages. Please >_<
#
# Feel free to fork and expand and/or add more languages as an example
# to why this would be horrible, and I'll add them here :)
# Ruby in English
if user.is_alive?
# send spam mail
@cimm
cimm / gist:1359553
Created November 11, 2011 22:44
Imports a folder in iPhoto
-- debugging
on log_event(themessage)
set theLine to (do shell script "date +'%Y-%m-%d %H:%M:%S'" as string) & " " & themessage
do shell script "echo " & theLine & " >> ~/Library/Logs/AppleScript-events.log"
end log_event
-- Extract the album name from the session file
on extractAlbumName(sessionContents)
set albumName to ""
set allLines to every paragraph of sessionContents
@cimm
cimm / gist:736953
Created December 10, 2010 22:56
Creates an Heroku dump and downloads the result, removing the old local backup if needed.
#!/usr/bin/env ruby
app = "your-heroku-app"
STDOUT.sync = true
start_time = Time.now
# Fail if the previous dump did not end well
if File.exist?("#{app}.dump.backup")
puts "\e[31mThe previous dump did not end well, check manually.\e[0m"
@cimm
cimm / gRaphael.js
Created July 28, 2010 18:40
Easiest way to draw a line graph with gRaphael
// Initialize the Raphael object
var r = Raphael("holder");
// Assign the values for the X axis
var x = [1, 2, 3, 4];
// Assign the values for the Y axis
var y = [1, 2, 1, 3];
// Draw a line chart (startX, startY, width, height, valuesX, valuesY)
r.g.linechart(0, 0, 300, 220, x, y);
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'gnuplot'
if ARGV[0]
source = ARGV[0]
else
puts "usage: ./gpx2image source_file"
exit(0)
@cimm
cimm / gist:463765
Created July 4, 2010 21:10
Creates an Heroku bundle and downloads the result, removing the old local backup if needed.
#!/usr/bin/env ruby
app = "your-heroku-app"
STDOUT.sync = true
start_time = Time.now
# Prepare old backup for rotate if needed
if File.exist?("#{app}.tar.gz.backup")
puts "\e[31mThe previous backup did not end well, check manually.\e[0m"
@cimm
cimm / train.rb
Last active September 4, 2015 13:35
Gets the NMBS/SNCB trains leaving from a given station in Belgium.
#!/usr/bin/env ruby
require 'rubygems'
require 'cgi'
require 'open-uri'
require 'hpricot'
current_time = Time.now.strftime("%H:%M")
url = ""
user_agent = "Mozilla/5.0 (X11; U; CrOS i686 9.10.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.253.0 Safari/532.5"