Skip to content

Instantly share code, notes, and snippets.

View matthiasg's full-sized avatar

matthiasg matthiasg

View GitHub Profile
@deandob
deandob / livestream
Created February 26, 2014 22:31
Node.JS function to remux mp4/h.264 video from an IP camera to a HTML5 video tag using FFMPEG
// Live video stream management for HTML5 video. Uses FFMPEG to connect to H.264 camera stream,
// Camera stream is remuxed to a MP4 stream for HTML5 video compatibility and segments are recorded for later playback
var liveStream = function (req, resp) { // handle each client request by instantiating a new FFMPEG instance
// For live streaming, create a fragmented MP4 file with empty moov (no seeking possible).
var reqUrl = url.parse(req.url, true)
var cameraName = typeof reqUrl.pathname === "string" ? reqUrl.pathname.substring(1) : undefined;
if (cameraName) {
try {
cameraName = decodeURIComponent(cameraName);

Consul Consistency

As Kyle brought up, Consul at the moment has a single known case of a potential inconsistency (Could be unknown cases lurking). Currently Consul works by electing a leader, who "leases" the position for LeaderLeaseTimeout interval. At each interval, it checks that a quorum of nodes still believes it to be the leader. At the same time, if a follower does not hear from the leader within randomInterva(HeartbeatTimeout, 2 * HeartbeatTimeout), it will start a new election.

<html>
<!-- You may need to download them from https://github.com/brix/crypto-js/tree/release-3.1.2/build -->
<script src="rollups/sha1.js"></script>
<script src='components/lib-typedarrays-min.js'></script>
<body>
<script>
function sha1sum() {
var oFile = document.getElementById('uploadFile').files[0];
var sha1 = CryptoJS.algo.SHA1.create();
var read = 0;
@xen0l
xen0l / gist:732fb7a6bb50ffbf0ba9
Created September 30, 2014 15:56
How to make QEMU guest-agent work on SmartOS
[root@smartos ~]# UUID="afe2f552-4a35-4c44-8855-a9bac10f27d2"
[root@smartos ~]# vmadm update ${UUID} qemu_extra_opts="-chardev socket,path=/tmp/vm.qga,server,nowait,id=qga0 -device virtio-serial -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0"
Successfully updated VM afe2f552-4a35-4c44-8855-a9bac10f27d2
[root@smartos ~]# vmadm boot ${UUID}
Successfully started VM afe2f552-4a35-4c44-8855-a9bac10f27d2
[root@smartos ~]# sleep 60 # Machine needs to boot up
[root@smartos ~]# echo '{"execute": "guest-ping" }' | socat stdio unix-connect:/zones/${UUID}/root/tmp/vm.qga # Is GA alive?
{"return": {}}
[root@smartos ~]# echo '{"execute": "guest-info" }' | socat stdio unix-connect:/zones/${UUID}/root/tmp/vm.qga # show information about GA
{"return": {"version": "0.12.1", "supported_commands": [{"enabled": true, "name": "guest-set-vcpus"}, {"enabled": true, "name": "guest-get-vcpus"}, {"enabled": true, "name": "guest-network-get-interfaces"}, {"enabled": true, "name": "guest-suspend-hybrid"}, {"enabled": tru
@WebReflection
WebReflection / gist:24c4c475bdeb59405e87
Last active February 15, 2016 15:56
setTimeout and setInterval extra arguments

Every single JavaScript engine supports standard timers *

These accept one or more extra argument by specs

for(var i = 0; i < 2; i++) {
  setTimeout(function (i) {
    console.log(i);
  }, 0, i); // <== see this?
}
@rdtsc
rdtsc / app.css
Created March 17, 2015 03:48
NW.js Windows PDF Printing Demo
body {
font-family: sans-serif;
}
section {
margin-bottom: 40px;
}
h1 {
font-size: 20px;
@ThatRendle
ThatRendle / MITEA.license
Created March 30, 2015 10:53
The "MIT Except Apple" License
The MIT-except-Apple License (MIT-EA)
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person (except
anybody associated with Apple Inc.) obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@benkulbertis
benkulbertis / cloudflare-update-record.sh
Last active February 25, 2025 10:56
Cloudflare API v4 Dynamic DNS Update in Bash
#!/bin/bash
# CHANGE THESE
auth_email="[email protected]"
auth_key="c2547eb745079dac9320b638f5e225cf483cc5cfdda41" # found in cloudflare account settings
zone_name="example.com"
record_name="www.example.com"
# MAYBE CHANGE THESE
ip=$(curl -s http://ipv4.icanhazip.com)
function SaferHTML(templateData) {
var s = templateData[0];
for (var i = 1; i < arguments.length; i++) {
var arg = String(arguments[i]);
// Escape special characters in the substitution.
s += arg.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
@senthilprabhut
senthilprabhut / md-colors.js
Last active June 22, 2016 20:31
Added md-fg, md-bg and md-bdr classes
/* Inspired from https://github.com/angular/material/pull/1599 and https://gist.github.com/SimeonC/1f6b6e52c9b14c4c7b63*/
(function () {
"use strict";
/**
* @ngdoc run
* @module mdColors
*
* @description
* This builds css styles like "md-default-theme md-accent md-fg" to allow use of the accent class to the foreground (css color attribute) where 'default' is the theme name
* Similarly, you can use "md-default-theme md-primary md-bg" to apply the primary class to background-color. Here, 'default' is the theme name.