Skip to content

Instantly share code, notes, and snippets.

View nvella's full-sized avatar
🚃
on a tram

Nick Vella nvella

🚃
on a tram
View GitHub Profile
@nvella
nvella / BookCopiesController.cs
Last active April 1, 2019 05:26
EntityFramework controller with composite primary key
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ProjectAPI.Models;
namespace ProjectAPI.Controllers
@nvella
nvella / ExceptionDemo.cs
Created January 29, 2019 09:47
Demo of exceptions
// This is our custom exception
public class TakenUsernameException : System.Exception
{
public TakenUsernameException() { }
public TakenUsernameException(string message) : base(message) { }
public TakenUsernameException(string message, System.Exception inner) : base(message, inner) { }
}
class MyApp {
@nvella
nvella / pavecraft-notify.js
Created September 18, 2018 07:03
Bot for sending pavecraft chat to the minecraft channel
const fetch = require('node-fetch');
const {spawn} = require('child_process');
const readline = require('readline');
const SERVER_LOG = '/home/minecraft/server/logs/latest.log';
const WEBHOOK = 'SLACK_WEBHOOK_HERE';
const REGEX = /^(\[\d\d:\d\d:\d\d\] \[.*\]: )((<[^ ]*\>)|([^ ]* (left|joined) the game))|(.*)(shot by|to death|cactus|drowned|experienced kinetic|removed an elytra|blew up|blown up|hit the ground|fell|doomed to fall|shot off|blown|squashed|flames|burned|burnt|fire|bang|lava|lightning|slain by|finished off|fireballed|killed by|starved|suffocated|squished|fell out|withered away|pummeled by|pummeled|died)/;
const tail = spawn('/usr/bin/tail', ['-n0', '-f', SERVER_LOG]);
const rl = readline.createInterface({input: tail.stdout});
@nvella
nvella / tests.py
Last active August 23, 2017 23:56
Test cases
IN: 2 x 3 + 2 ^ * 4 x 1 - x 2 + * * + 3 x 1 + * + 4 x * - 6 +
EXP: 6x^2 + 15x + 19
OUT: 6x^2 + 15x + 19
PASS
IN: x 2 ^ 3 - 1 2 x * - *
EXP: -2x^3 + x^2 + 6x - 3
OUT: -2x^3 + x^2 + 6x - 3
PASS
@nvella
nvella / hass.service
Created September 18, 2016 10:17
Home Assistant systemd
[Unit]
Description=Home Assistant
After=network.target
[Service]
Type=simple
User=homeassist
ExecStart=/home/homeassist/run_hass.sh
[Install]