Skip to content

Instantly share code, notes, and snippets.

View stpe's full-sized avatar
👋
🏎💨

Stefan Pettersson stpe

👋
🏎💨
View GitHub Profile
@stpe
stpe / youtube_topicIDs.md
Last active April 6, 2024 22:36
YouTube Topic IDs

Music topics

  • /m/04rlf Music
  • /m/05fw6t Children's music
  • /m/02mscn Christian music
  • /m/0ggq0m Classical music
  • /m/01lyv Country
  • /m/02lkt Electronic music
  • /m/0glt670 Hip hop music
  • /m/05rwpb Independent music
@stpe
stpe / youtube_videoCategories.md
Last active November 15, 2016 10:22
YouTube Video Categories

Per regionCode.

US

  • Film & Animation
  • Autos & Vehicles
  • Music
  • Pets & Animals
  • Sports
  • Short Movies
@stpe
stpe / slack-export-emoji-statistics.js
Created March 10, 2016 09:54
Parse Slack export to show top list of most popular emojis
"use strict";
var fs = require("fs");
var path = require("path");
var dir = "./export";
let count = fs.readdirSync(dir)
// we only want channel sub-directories
.filter(file => fs.statSync(path.join(dir, file)).isDirectory())
@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",
@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 / 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 / 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 / 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 / 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 / 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: