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_audioLanguages.json
Created January 26, 2017 16:03
Youtube Audio Languages
{
"zxx": "Not applicable",
"ab": "Abkhazian",
"aa": "Afar",
"af": "Afrikaans",
"sq": "Albanian",
"ase": "American Sign Language",
"am": "Amharic",
"ar": "Arabic",
"arc": "Aramaic",
@stpe
stpe / bitly_get_access_token.sh
Last active September 4, 2023 19:11
Bitly Get Access Token
curl -u "myemail@domain.com:xyz123mypassword" -X POST "https://api-ssl.bitly.com/oauth/access_token"
@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 / 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 / youtube_videoCategories.json
Last active October 15, 2021 06:20
YouTube Video Categories JSON array
[
{
"id": "1",
"title": "Film & Animation"
},
{
"id": "2",
"title": "Autos & Vehicles"
},
{
@stpe
stpe / clearbit-signature-validation.ts
Created May 28, 2020 09:32
How to calculate Clearbit API webhook X-Request-Signature in Node.js / JavaScript / TypeScript
import * as crypto from 'crypto';
export class ClearbitSignatureValidation {
static getSignature(raw_body: string, signature: string): string {
const signature_without_prefix = signature.replace(/^(sk\_)/, '');
return (
'sha1=' +
crypto
.createHmac('sha1', signature_without_prefix)
xargs -n 1 -I{} \
 sh -c " \
 curl -s -X GET \
 https://api-ssl.bitly.com/v4/bitlinks/bit.ly%2F2{}/clicks/summary \
 -H 'Authorization: Bearer ad7ecf6cd10e8f072651f00cf90e2bc983a4a974' \
 | jq .total_clicks" \
< shortlinks.txt
@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)