Skip to content

Instantly share code, notes, and snippets.

View svrooij's full-sized avatar

Stephan van Rooij svrooij

View GitHub Profile
@svrooij
svrooij / mqtt.py
Created March 6, 2020 11:12
MQTT Lights for diyhue
#!/usr/bin/env python
import signal
import paho.mqtt.client as mqtt
import json
import sys
# Parameters
discoveryPrefix = "homeassistant" # Configurable
mqttServer = "192.168.x.x" # user input
@svrooij
svrooij / Extending IQueryable.md
Created November 13, 2019 13:51
Select some properties based on $select query
@svrooij
svrooij / Certificates.cs
Last active November 26, 2023 11:20
C# generate X509Certificate2
/* By Stephan van Rooij
* See https://svrooij.nl/2018/04/generate-x509certificate2-in-csharp/
*/
using System;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using Org.BouncyCastle.X509;
using Org.BouncyCastle.Utilities;
@svrooij
svrooij / Startup.cs
Created August 4, 2017 14:51
Publish AspNetCore behind nginx (and terminate HTTPS)
...
using Microsoft.AspNetCore.HttpOverrides;
...
namespace HttpOverrides.Sample
{
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
@svrooij
svrooij / StringExtensions.cs
Created June 27, 2016 10:32
Youtube link to Embed code in C#
using System.Text.RegularExpressions;
namespace YourNamespace
{
internal static class StringExtensions
{
//http://stackoverflow.com/questions/3652046/c-sharp-regex-to-get-video-id-from-youtube-and-vimeo-by-url
static readonly Regex YoutubeVideoRegex = new Regex(@"youtu(?:\.be|be\.com)/(?:(.*)v(/|=)|(.*/)?)([a-zA-Z0-9-_]+)", RegexOptions.IgnoreCase);
static readonly Regex VimeoVideoRegex = new Regex(@"vimeo\.com/(?:.*#|.*/videos/)?([0-9]+)", RegexOptions.IgnoreCase | RegexOptions.Multiline);
// Use as
@svrooij
svrooij / Blog.cs
Created June 15, 2016 13:05
EntityFramework default properties
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel;
namespace YourNamespace
{
[Table("Blogs")]
// We inherit the EntityBase class here (with Id, CreatedAt and UpdatedAt)
@svrooij
svrooij / gist:837c7d139c3813c10200
Created January 18, 2016 19:47
Verifying that +svrooij is my blockchain ID. https://onename.com/svrooij
Verifying that +svrooij is my blockchain ID. https://onename.com/svrooij
@svrooij
svrooij / Ninjablock_to_local_mqtt.sh
Last active January 14, 2021 02:44
Ninjablock to local MQTT server
# This describes how you can connect your ninjablock to your own mqtt server
# It is not the best manual, so please provide feedback
# First of you have to start with the "beta" image found at: https://discuss.ninjablocks.com/t/unstable-brand-new-image-for-your-block/1666
# Or direct link if you must: http://ninjablocks-nightly.s3.amazonaws.com/block/ubuntu_armhf_trusty_sterling_block-unstable_2014-07-16_1044.img.gz
# Then put that on an sdcard (like you normally would)
# Put it in the ninjablock
# Let it boot!!
# power off (upon first boot it creates a ssh key (needed for enabling ssh))
# power on
@svrooij
svrooij / functions.php
Created May 1, 2015 18:31
Wordpress email with Gmail
// add the following to your themes functions.php file
// Off course, you should never change the parent theme and put all the changes in a child theme
add_action( 'phpmailer_init', 'gmail_phpmailer_init' );
function gmail_phpmailer_init( PHPMailer $phpmailer ) {
$phpmailer->Host = 'smtp.gmail.com';
$phpmailer->Port = 587;
$phpmailer->Username = 'pietje_puk@gmail.com'; // Full username (with @gmail.com)
$phpmailer->Password = 'your_secret_password'; // Your own password
$phpmailer->SMTPAuth = true; // Gmail requires authentication
@svrooij
svrooij / index.html
Created April 26, 2015 09:36
Improve your mobile webapp
<html>
<head>
<title>Your nice webapp</title>
<!-- add from here -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="iOS 8 web app">
<meta name="viewport" content="initial-scale=1">
</head>