Skip to content

Instantly share code, notes, and snippets.

@jdoxey
jdoxey / image_to_plantuml_sprite.sh
Created April 25, 2020 06:45
Generate PlantUML sprite from any image
#!/bin/sh
# requires imagemagick and plantuml
convert $1 -colorspace Gray -resize 16x16 -flatten /tmp/sprite.png
java -jar ~/bin/plantuml.jar -encodesprite 16 /tmp/sprite.png
@jdoxey
jdoxey / generatePKCECodeVerifier.js
Last active February 9, 2020 22:18
OAuth2 and OIDC now recommend that a single page app (SPA) should use the authorization code flow with the addition of PKCE to strengthen token handoff. I didn't find a simple code example of generating the code_verifier in JavaScript in a browser so I created this. It is an implementation of the method suggested in the PKCE spec (https://tools.…
function generatePKCECodeVerifier() {
var buffer = new ArrayBuffer(96); // 96 bytes creates a 128 character base64 encoded string
var uint8Array = new Uint8Array(buffer); // Uint8 makes getRandomValues choose numbers betwee 0 and 255
(window.crypto || window.msCrypto).getRandomValues(uint8Array);
var binaryString = String.fromCharCode.apply(null, uint8Array); // Utilise 'apply' converting array to function params
return btoa(binaryString).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); // base64url encoding
}
export PROMPT="[%t] %B%F{green}%n@%m%f:%F{blue}%c %# %f%b"
#include <pebble.h>
int main(void) {
// setup
// start run loop
// cleanup
}
#include <pebble.h>
int main(void) {
// setup
Window *first_window = window_create();
window_stack_push(first_window, true);
// start run loop
app_event_loop();
TextLayer *hello_text_layer = text_layer_create(GRect(10, 10, 100, 40));
text_layer_set_text(hello_text_layer, "Hello");
layer_add_child(window_get_root_layer(first_window), text_layer_get_layer(hello_text_layer));
text_layer_destroy(hello_text_layer);
Pebble.addEventListener("ready", function (event) {
console.log("*** Our JavaScript Running");
});
Pebble.sendAppMessage({ 0: "From JavaScript" });
static void message_received(DictionaryIterator *iterator, void *context) {
char *message = dict_find(iterator, 0)->value->cstring;
APP_LOG(APP_LOG_LEVEL_DEBUG, "Got message: %s", message);
}