Skip to content

Instantly share code, notes, and snippets.

View edwinm's full-sized avatar
🔌
Playing with electronics and learning MicroPython

Edwin Martin edwinm

🔌
Playing with electronics and learning MicroPython
View GitHub Profile
// by Simon Sturmer
// TypeScript: Building a better EventEmitter
// https://www.youtube.com/watch?v=Pl7pDjWd830
// Creative Commons-licence
type Listener<T extends Array<any>> = (...args: T) => void;
export class Eventemitter<EventMap extends Record<string, Array<any>>> {
private eventListeners: {
[K in keyof EventMap]?: Set<Listener<EventMap[K]>>;
// by Simon Sturmer
// TypeScript Wizardry: Recursive Template Literals
// https://www.youtube.com/watch?v=B7ygRIQcQPE
// Creative Commons-licence
const locales = {
en_us: {
hello:'Hi {user}',
greetings: {
morning:'Good morning {user}',
@edwinm
edwinm / pretty-print-xml.ts
Created October 14, 2022 08:35
Pretty Print XML
prettyXml(xml: string) {
try {
const domParser = new DOMParser();
const xmlDom = domParser.parseFromString(xml, 'application/xml');
const xsltDom = domParser.parseFromString(
`<xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform>
<xsl:strip-space elements="*"/>
<xsl:template match="para[content-style][not(text())]">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>

Introductie Web Components

Web components is een W3C webstandaard waarmee je, eenvoudig gezegd, je eigen HTML-tags kunt maken. Het toevoegen van een plattegrond op je webpagina kan dan zo eenvoudig zijn als het toevoegen van deze tag:

<g-map latitude="52.3812258" longitude="4.9001255"></g-map>

Keybase proof

I hereby claim:

  • I am edwinm on github.
  • I am edwinm (https://keybase.io/edwinm) on keybase.
  • I have a public key ASBPgn6mwoc7z_qfYhbiO132xGcNqB9i6YMvppwtFu36fgo

To claim this, I am signing this object:

Verifying that +edwinm is my blockchain ID. https://onename.com/edwinm
@edwinm
edwinm / mts2mp4.sh
Created May 8, 2013 07:36
Convert .mts to .mp4 video files.
#!/bin/bash
if [ ! $# == 1 ]; then
echo "Usage: $0 <path to mts-files>"
exit
fi
cd "$1"
for FILE in `ls "$1"`
@edwinm
edwinm / power.php
Created November 25, 2009 22:04
Logs in to US Robotics router and turns on computer with Wake-on-lan
<html>
<head>
<title>Power on</title>
</head>
<body>
<h3>Power on</h3>
<p>Powering on machine <?php echo $mac ?></p>
@edwinm
edwinm / webcam.c
Created November 25, 2009 21:59
Old-school webcam by using server-push.
// webcam.c
// Author E. Martin
// July 27th 1997
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/time.h>
@edwinm
edwinm / Small AJAX function
Created November 11, 2009 15:22
Small AJAX function, only supports GET, no caching.
/**
* Very small Ajax function.
*
* Bugs: doesn't support POST, only GET.
*
* @param {String} url
* @param {Function} fn
*/
function fetchXML(url, fn){
var xmlHttp = null;