Skip to content

Instantly share code, notes, and snippets.

@MatthewRiggott
MatthewRiggott / Caller.js
Created June 1, 2019 18:20
Run string as Function with args from web worker
sendCode() {
const code = this.state.code;
const lastRowIndex = this.refs.aceEditor.editor.session.getLength() - 1;
const functionBody = code.split('\n').filter((l, i) => { if(!(i == 0 || i == lastRowIndex )){ return l } }).join("\n");
const question = this.state.question;
const functionName = question.functionName;
const params = question.args.map(q => q.name);
const testArgs = question.tests.map(t => t.input);
const interpreter = new Worker();
@MatthewRiggott
MatthewRiggott / debounce.js
Created May 29, 2019 16:45
Javascript debounce
// Credit to underscore.js
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
@MatthewRiggott
MatthewRiggott / .editorconfig
Last active March 20, 2019 01:47
C# .net standard editorconfig (except for spaces & indent size=2)
# See https://github.com/RehanSaeed/EditorConfig for updates to this file.
# See http://EditorConfig.org for more information about .editorconfig files.
#################
# Common Settings
#################
# This file is the top-most EditorConfig file
root = true
@MatthewRiggott
MatthewRiggott / standup.ps1
Created February 28, 2019 19:29
Automate weekly standup with the power of microsoft speech
# power shell script to use microsoft speech to automate weekly standup
Add-Type -AssemblyName System.Speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$since = "1 weeks ago"
$user = git config user.name
$projectPath = "$env:USERPROFILE\Documents\Visual Studio 2017\Projects"
$projects = New-Object "System.Collections.Generic.List[String]"
$projects.Add("project1")
$projects.Add("my_other_project")
// glued a couple stack overflows together
function CELLFORMULA(ref) {
var sheet = SpreadsheetApp.getActiveSheet();
var formula = SpreadsheetApp.getActiveRange().getFormula();
var args = formula.match(/=\w+\((.*)\)/i)[1].split('!');
try {
if (args.length == 1) {
var range = sheet.getRange(args[0]);
}
@MatthewRiggott
MatthewRiggott / Elastic.sh
Created May 22, 2018 20:53
Run Elastic Search in shell with verbose output
# For Elastic Search version 5.6
# Credit to https://opensourceconnections.com/blog/2016/04/21/run-elasticsearch-in-your-shell/
# This mostly worked, I had to remove the argument for default.path.home and prepend each arg with -E (ES version 5.0+ breaking change)
#
# Add the following to your path and load (for ubuntu, actual paths may vary)
# Elastic Search Settings --
# ES_JAVA_OPTS="-Des.logger.level=INFO"
# LOG_DIR="/var/log/elasticsearch"
# DATA_DIR="/var/lib/elasticsearch"
# CONF_DIR="/etc/elasticsearch"
@MatthewRiggott
MatthewRiggott / launch.json
Created May 17, 2018 14:55
Vagrant PHP Xdebug VS Code
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
@MatthewRiggott
MatthewRiggott / Caesar Cypher
Created May 3, 2015 19:22
Ruby code that takes a string with an integer value and shifts each character by the integer value.
def caesar_cypher(word, shift_amount)
result = ""
word.each_char do |character|
letter_value = character.ord
if (97..122).include?(letter_value)
# shift lowercase letters
result += (((letter_value - 97 + shift_amount) % 26) + 97).chr
elsif (65..90).include?(letter_value)
# shift the uppercase letters