Skip to content

Instantly share code, notes, and snippets.

View mpj's full-sized avatar

Mattias Petter Johansson mpj

View GitHub Profile
@mpj
mpj / upload.rb
Created November 7, 2010 21:39
Very simple example of accepting an XHR upload in Sinatra
post '/upload' do
# This accepts the XHR uploads and save the file into the script home directory
string_io = request.body # will return a StringIO
data_bytes = string_io.read # read the stream as bytes
filename = env['HTTP_X_FILE_NAME'] # This will be the actual filename of the uploaded file
# Write it to disk...
// ==========================================================================
// Project: Jaysprout
// Copyright: ©2011 My Company, Inc.
// ==========================================================================
/*globals Jaysprout */
var Jaysprout = SC.Application.create();
Jaysprout.Clip = SC.Object.extend({
title: null,
source 'http://rubygems.org'
gem 'rails', '3.0.6'
gem 'warden' # Rack authentication, required by devise
gem 'devise', :git => 'https://github.com/plataformatec/devise.git',
:branch => 'master'
# Authentication gem, need the 1.2 version from
# github to make the omniauth integration work
gem 'oa-oauth', :require => 'omniauth/oauth' # Authentication gem
#! /bin/bash
#
# xvfb Start/Stop Xvfb server.
#
# chkconfig: 345 91 10
# description: Xvfb is a virtual framebuffer X server. Xvfb is an X server that can run on machines with no display hardware and no physical input devices.
# processname: xvfb
# pidfile: ~/xvfb_${DISPLAY:1}.pid
DISPLAY=:99.0 firefox http://example.org
# For kicks, you can make a screenshot to see it working
xwd -root -display :99.0 -out screenshot.xwd
convert screenshot.wxd ~/screenshot.jpg
# Exit SSH session and download the
# screenshot to your local computer via SCP:
exit
scp -i yourkeypairfile.pem ubuntu@public.dns.hostname.of.instance:screenshot.jpg screenshot.jpg
// bajs
@mpj
mpj / timespantostring.rb
Created August 18, 2011 09:00
Converting timespan to string.
// ==UserScript==
// @name BetterTATMIN
// @namespace http://tat.se
// @version 0.0.1
// @description Fixes some annoyances of the time reporting tool to make it nicer.
// @include http://www01mmxlabvm/*
// @copyright 2011, RIM TAT AB
// ==/UserScript==
var ENABLE_FREE_FRIDAYS = true;
@mpj
mpj / gist:1390054
Created November 23, 2011 22:00
Calling mongodb in node
var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
var BSON = require('mongodb').BSON;
var ObjectID = require('mongodb').ObjectID;
exports.index = function(req, res) {
this.db = new Db('node-hipchat-logger',
new Server('localhost', 27017, {auto_reconnect: true}, {}));
'Graph request succeeds': when(FacebookProvider, {
get_me_called_with: 'fbtoken99887755',
should_return: {
id: '640798226',
name: 'Mattias Petter Johansson'
},
after_calling: {
@mpj
mpj / gist:1739244
Created February 4, 2012 18:04
Example of findNearbyPlaceName
From: http://api.geonames.org/findNearbyPlaceNameJSON?lat=56.8134071&lng=12.6718877&username=demo
{
geonames:[
{
countryName:"Sweden",
adminCode1:"06",
fclName:"city, village,...",
countryCode:"SE",
lng:12.65,
fcodeName:"populated place",