Skip to content

Instantly share code, notes, and snippets.

View peppelorum's full-sized avatar

Peppe Hämeenniemi peppelorum

View GitHub Profile
@peppelorum
peppelorum / sidecar.app
Created May 2, 2022 08:59
How to activate a certain display on MacOS with an Apple Script
-- How to activate a certain display on MacOS with an Apple Script.
tell application "System Preferences"
if not running then run
activate
reveal anchor "displaysArrangementTab" of pane id "com.apple.preference.displays"
tell application "System Events"
tell application process "System Preferences"
tell first window
@peppelorum
peppelorum / gist:faff4201037796ad4058fa4ac87e95c8
Created March 17, 2017 11:58 — forked from rb2k/gist:8372402
A jenkins script to clean up workspaces on slaves
// Check if a slave has < 10 GB of free space, wipe out workspaces if it does
import hudson.model.*;
import hudson.util.*;
import jenkins.model.*;
import hudson.FilePath.FileCallable;
import hudson.slaves.OfflineCause;
import hudson.node_monitors.*;
for (node in Jenkins.instance.nodes) {

Keybase proof

I hereby claim:

  • I am peppelorum on github.
  • I am peppelorum (https://keybase.io/peppelorum) on keybase.
  • I have a public key whose fingerprint is F9FB 8E92 FC0A 7FA0 3A9B D36C EC26 DF30 3C6E 578F

To claim this, I am signing this object:

@peppelorum
peppelorum / app.js
Created October 2, 2014 11:23
http inject on cors fails
oscarApp.factory('sessionInjector', ['Auth', function(Auth) {
var sessionInjector = {
request: function(config) {
if (Auth.isLoggedIn()) {
config.headers['x-session-token'] = Auth.data.apiKey;
}
return config;
}
};
return sessionInjector;
@peppelorum
peppelorum / gist:9047753
Last active August 29, 2015 13:56
Removes duplicates in WeLovePublicService DB
from django.db.models import Count
dupes = Episode.objects.values('url').annotate(count=Count('id')).order_by().filter(count__gt=1)
Episode.objects.filter(url__in=[item['url'] for item in dupes]).delete()
from django.core.cache import cache
cache.clear()
@peppelorum
peppelorum / gist:6641745
Created September 20, 2013 18:29
Comparing an unsorted vs sorted list in Javascript
var arr = [];
var l = 10000000;
var tmp;
for (var i = 0; i < l; i++) {
arr.push(Math.round(Math.random() * l));
}
console.time('Unsorted timer');
@peppelorum
peppelorum / gist:6641396
Created September 20, 2013 18:03
Comparing looping through a unsorted vs sorted list in Python
import random
import time
a = [int(random.random() * 1000) for _ in xrange(10000000)]
program_starts = time.time()
for item in a:
tmp = False
now = time.time()
@peppelorum
peppelorum / gist:5856691
Created June 25, 2013 07:42
Validera personnummer med Javascript (med Luhn) JSLint-fixad funktion från http://maaets.blogspot.se/2012/06/validera-personnummer-med-javascript.html
function(input) {
// Check valid length & form
if (!input) { return false; }
if (input.indexOf('-') === -1) {
if (input.length === 10) {
input = input.slice(0, 6) + "-" + input.slice(6);
} else {
input = input.slice(0, 8) + "-" + input.slice(8);
}
@peppelorum
peppelorum / gist:5523611
Created May 6, 2013 06:19
Rpartition exempel
>>> 'http://www.svtplay.se/video/52776/mysteriet-med-den-forsvunna-jellybean-listan?tab=episodes&sida=100'.rpartition('/')
('http://www.svtplay.se/video/52776', '/', 'mysteriet-med-den-forsvunna-jellybean-listan?tab=episodes&sida=100')
>>> 'http://www.svtplay.se/video/52776/mysteriet-med-den-forsvunna-jellybean-listan?tab=episodes&sida=100'.rpartition('/')[0]
'http://www.svtplay.se/video/52776'
@peppelorum
peppelorum / gist:5520468
Created May 5, 2013 10:47
Consuming WeLovePublicService's SVTPlay API with requests and rethinkdb
import requests
from rethinkdb.errors import RqlRuntimeError
import rethinkdb as r
r.connect('localhost', 28015).repl()
try:
r.db('wlps').table_create('episode').run()
except RqlRuntimeError:
pass