Skip to content

Instantly share code, notes, and snippets.

View matthiasg's full-sized avatar

matthiasg matthiasg

View GitHub Profile
@matthiasg
matthiasg / playground.rs
Last active March 21, 2019 10:42 — forked from rust-play/playground.rs
Code shared from the Rust Playground
struct MyType {
value: u32
}
impl MyType {
fn new() -> MyType {
MyType {
value: 1
}
}
@matthiasg
matthiasg / gist:3cefcb5e6d51ba66995e3011b0175a32
Created February 25, 2019 15:50 — forked from xen0l/gist:732fb7a6bb50ffbf0ba9
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
@matthiasg
matthiasg / gist:b0e1511e6db140119cdf24ddc1743c0b
Created December 4, 2017 07:15 — forked from dalethedeveloper/gist:1503252
Mobile Device Detection via User Agent RegEx

#Mobile Device Detection via User Agent RegEx

Yes, it is nearly 2012 and this exercise has been done to death in every imaginable language. For my own purposes I needed to get the majority of non-desktop devices on to a trimmed down, mobile optimized version of a site. I decided to try and chase down an up-to-date RegEx of the simplest thing that could possibly work.

I arrived at my current solution after analyzing 12 months of traffic over 30+ US based entertainment properties (5.8M+ visitors) from Jan - Dec 2011.

The numbers solidified my thoughts on the irrelevancy of including browsers/OSes such as Nokia, Samsung, Maemo, Symbian, Ipaq, Avant, Zino, Bolt, Iris, etc. The brass tacks of the matter is that you certainly could support these obscure beasts, but are you really going to test your site on them? Heck, could you even find one?! Unless the folks that pay you are die hard Treo users my guess is "No".

Interestingly enough my research shows that /Mobile/ is more efficient than **/iP(

@matthiasg
matthiasg / TestPattern.cpp
Created July 21, 2017 14:38 — forked from roxlu/TestPattern.cpp
Example usage of X264. We create a raw YUV pattern and encode it with x264.
#include <cmath>
#include <assert.h>
#include <core/TestPattern.h>
TestPattern::TestPattern()
:w(0)
,h(0)
,frame_num(0)
,duration(0)
@matthiasg
matthiasg / _decimal.scss
Created March 25, 2017 14:48 — forked from terkel/_decimal.scss
Rounding decimals in Sass
// _decimal.scss | MIT License | gist.github.com/terkel/4373420
// Round a number to specified digits.
//
// @param {Number} $number A number to round
// @param {Number} [$digits:0] Digits to output
// @param {String} [$mode:round] (round|ceil|floor) How to round a number
// @return {Number} A rounded number
// @example
// decimal-round(0.333) => 0
@matthiasg
matthiasg / haproxy.cfg
Created August 9, 2016 19:29 — forked from ryzy/haproxy.cfg
HAProxy - essentials for HTTP/2
frontend https-in
mode tcp
bind *:443 ssl crt /etc/ssl/dummy.pem alpn h2,http/1.1
use_backend nodes-http2 if { ssl_fc_alpn -i h2 }
default_backend nodes-http
backend nodes-http
server node1 web.server:80 check
backend nodes-http2
@matthiasg
matthiasg / gist:2b8748cfdf919ce77c3fd0438613cee6
Created April 12, 2016 21:11 — forked from robinloxley1/gist:7ea7c4f37a3413b1ca16
sample elasticsearch query to sort parent based on child field
{
"query":{
"has_child":{
"query":{
"function_score":{
"functions":[
{
"field_value_factor":{
"factor":1,
"field":"count"
@matthiasg
matthiasg / basicServiceWorker.js
Created November 30, 2015 09:44 — forked from adactio/basicServiceWorker.js
A basic Service Worker, for use on, say, a blog.
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function() {
// Update 'version' if you need to refresh the cache
var staticCacheName = 'static';
var version = 'v1::';
@matthiasg
matthiasg / app.css
Last active September 14, 2015 13:20 — forked from rdtsc/app.css
NW.js Windows PDF Printing Demo
body {
font-family: sans-serif;
}
section {
margin-bottom: 40px;
}
h1 {
font-size: 20px;
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