Skip to content

Instantly share code, notes, and snippets.

View snobu's full-sized avatar

Adrian Calinescu snobu

View GitHub Profile
@snobu
snobu / Html5VideoEvents.html
Last active June 1, 2017 09:03
HTML5 video events to App Insights (sending every 13 seconds or so)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>HTML5 video events to App Insights</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript">
var appInsights=window.appInsights||function(config){
@snobu
snobu / oneliners.sh
Created June 10, 2017 14:20
oneliners
# Eat up 90% of free memory
stress --vm-bytes $(awk '/MemFree/{printf "%d\n", $2 * 0.9;}' < /proc/meminfo)k --vm-keep -m 1
FROM https://community.hortonworks.com/articles/69823/creating-shared-access-signature-sas-for-posting-d.html
Short Description:
Step by step instructions for creating a SAS token to authorize HTTP clients for Microsoft's Azure Event Hubs
Article
First ... if you need background Azure Event Hubs go here: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-overview
@snobu
snobu / gist:5ad4959e2706e56a11dc3ab8ca585054
Created June 26, 2017 09:50
LFCS-could-happen-to-you
UPSTART
Enabling / Disabling a service
To toggle a service from starting or stopping permanently you would need to:
echo manual | sudo tee /etc/init/SERVICE.override
------------------------------------------------------------------------
https://askubuntu.com/questions/19320/how-to-enable-or-disable-services
------------------------------------------------------------------------
Grep uncommented lines in config file:
@snobu
snobu / gist:e56df03584afc84d29ced8670c6b355c
Last active September 20, 2017 10:05 — forked from webarthur/gist:0ed27fbf811bbcc94e7c7c476b5d8f91
Force apt-get to IPv4 because sometimes you just have to
sudo echo "Acquire::ForceIPv4 \"true\";" > /etc/apt/apt.conf.d/99force-ipv4
@snobu
snobu / eventhub_make_sas_token.js
Created September 20, 2017 10:03
Make Event Hub SAS Token
// Create a SAS token
// See http://msdn.microsoft.com/library/azure/dn170477.aspx
const moment = require('moment');
const crypto = require('crypto');
function create_sas_token(uri, key_name, key)
{
// Token expires in one hour
var expiry = moment().add(7, 'days').unix();
@snobu
snobu / ignore_cert_validation.ps1
Created October 12, 2017 17:08
PowerShell call service without cert validation
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $True }
$url = 'https://self-signed.badssl.com/'
$apiReq = [System.Net.HttpWebRequest]::CreateHttp($url)
$apiRes = $apiReq.GetResponse()
Out-File -Encoding Ascii -FilePath $res -InputObject $(ConvertTo-Json $apiRes)
@snobu
snobu / captureCanvasFrame.js
Created October 12, 2017 22:58
Capture canvas frame to byte stream for Face API
function captureVideoFrame(video, format) {
if (typeof video === 'string') {
video = document.getElementById(video);
}
format = format || 'jpeg';
if (!video || (format !== 'png' && format !== 'jpeg')) {
return false;
}
@snobu
snobu / asyncawait.js
Created October 30, 2017 19:07
Node async await ES2017
async function makeRequest() {
// npm install async-request
let request = require('async-request'), response;
try {
response = await request('https://istrumpstillpresident.io/version', {
headers: {'Accept': 'application/json'}
});
}
catch(e) {
@snobu
snobu / extracts.js
Created November 20, 2017 14:53
Extract article text from Wikipedia API
case 'about_roedu':
let wikipediaUrl = 'https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exlimit=max&explaintext&exintro&titles=RoEduNet&redirects=';
const request = require('request');
request(wikipediaUrl, function (error, response, body) {
context.log('error:', error); // Print the error if one occurred
context.log('statusCode:', response && response.statusCode);
context.log('body:', body);
let jsonRes = JSON.parse(body);
let page = Object.keys(jsonRes.query.pages)[0];
let pageText = jsonRes.query.pages[page].extract;