Skip to content

Instantly share code, notes, and snippets.

View stpe's full-sized avatar
👋
🏎💨

Stefan Pettersson stpe

👋
🏎💨
View GitHub Profile
@stpe
stpe / mantisconnect_json.php
Created March 17, 2012 22:26
Simple JSON wrapper of Mantis SOAP API
<?php
/**
* Example usage (using jQuery):
* var url = "/path/mantisconnect_json.php?name=mc_project_get_issues&project_id=0&page_number=1&per_page=10";
* $.getJSON(url, function(data) {
* $.each(data, function() {
* console.log(data.id + ': ' data.summary);
* });
* });
*/
@stpe
stpe / gist:2949924
Created June 18, 2012 18:38
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@stpe
stpe / snippet.md
Created June 19, 2012 07:58 — forked from harthur/snippet.md
console.log() key binding for Sublime Text 2

Go to Sublime Text 2 > Preferences > Key Bindings - User and add this JSON to the file:

[
  {
    "keys": ["super+shift+l"],
    "command": "insert_snippet",
    "args": {
      "contents": "console.log(${1:}$SELECTION);${0}"
 }, 
@stpe
stpe / TextOverflowModeFill-bug.c
Last active January 2, 2016 14:29
Code to reproduce GTextOverflowModeFill bug when word is wrapped starting with lowercase 'j' (using PebbleSDK-2.0-BETA4)
/*
Complete buildable project containing minimum sample code to reproduce bug:
https://dl.dropboxusercontent.com/u/20181/TextOverflowModeFill-bug.zip
Bug description:
Using a TextLayer with GTextOverflowModeFill seems to position the
leading 'j' out of place in wrapped words starting with 'j'.
Example screenshot of the 'j' out of place:
@stpe
stpe / Pebble wscript VERSION_LABEL
Created January 21, 2014 09:30
Modified Pebble wscript file. Read appinfo.json and generates appinfo.h which contain a define for VERSION_LABEL. http://forums.getpebble.com/discussion/10405/how-do-i-get-my-app-version-in-c-code
import json
top = '.'
out = 'build'
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
ctx.load('pebble_sdk')
@stpe
stpe / interval-sum.js
Created April 6, 2014 20:23
Using Array.prototype.reduce; Given an array of values, returns array of the sums of the values per INTERVAL.
var INTERVAL = 5;
var list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
list.reduce(function(result, value, index) {
var i = Math.floor(index/INTERVAL);
result[i] ? result[i] += value : result[i] = value;
return result;
}, []);
// Output: [15, 40, 11]
@stpe
stpe / isValidSwedishPIN.js
Last active February 17, 2020 20:20
Validate Swedish Personal Identity Number (personnummer) using checksum
// validate Swedish Personal Identity Number (personnummer) using checksum
// note: this is somewhat simplified because it does not take into account
// that the date of the number is valid (e.g. "000000-0000" does return as true)
function isValidSwedishPIN(pin) {
pin = pin
.replace(/\D/g, "") // strip out all but digits
.split("") // convert string to array
.reverse() // reverse order for Luhn
.slice(0, 10); // keep only 10 digits (i.e. 1977 becomes 77)
@stpe
stpe / blodcentralen.json
Created June 3, 2015 08:57
blodlager json
{
"@attributes": {
"BloodBankCode": "021"
},
"RunTime": "2015-06-03T10:48:04",
"StockLevel": [
{
"@attributes": {
"BloodGroup": "0+"
},
@stpe
stpe / get.js
Created September 9, 2015 09:47
Get nested object properties (just another take on implementation)
function get(obj, path) {
var parts = path.split(/\]\[|\]\.|\[|\]|\./);
return parts
.reduce(function(o, x) {
return (typeof o == "undefined" || o === null) ? x : o[x];
}, obj);
}
// example: get(obj, "prop.foo[0][2].bar[3].zoom")
@stpe
stpe / hyperiterativ-form-example.json
Last active February 19, 2016 23:14
Hyperiterativ prototypning med Google Spreadsheets
{
"conditions": [
{
"id": "D001",
"value": "barn"
}
],
"id": "PERSONNUMMERID",
"label": "Personnummer för barnet",
"placeholder": "ååååmmddxxxx",