Skip to content

Instantly share code, notes, and snippets.

View jennings's full-sized avatar
🦄
What a mess I've made

Stephen Jennings jennings

🦄
What a mess I've made
View GitHub Profile
@jennings
jennings / ThrowVsThrowEx.cs
Last active March 9, 2018 19:59
Demonstrates how `throw ex` replaces the stack trace in an exception, while `throw` preserves it.
using System;
class Program
{
static void One() { Two(); }
static void Two() { Three(); }
static void Three() { throw new Exception("Error"); }
static void Main(string[] args)
{
@jennings
jennings / dotenv.rb
Last active January 28, 2018 04:50
Executes a command after adding a `.env` file to the environment. This is probably terribly unsafe.
#!/usr/bin/env ruby
# usage: dotenv irb
begin
File.foreach('.env') do |line|
line = line.strip
unless line.start_with?('#')
parts = line.split '=', 2
if parts.length == 2
// paste this into a LINQPad C# Program
void Main()
{
var str = @"Key1=Value1
Key2:Key3=Value2";
var strings = str.Split(new []{"\r\n"}, StringSplitOptions.None)
.Select(s => s.Split(new[]{'='}, 2));
@jennings
jennings / CSharp_Throw_vs_ThrowEx.cs
Last active September 19, 2017 22:42
`throw` vs. `throw ex` in C#
using System;
namespace ConsoleApplication1
{
public class Program
{
public static void Main()
{
try
{
# Truncate paths in the prompt to 2 characters so long directories don't take up the whole window
function Prompt {
$path = $ExecutionContext.SessionState.Path.CurrentLocation
$segment = Split-path -Leaf $path
$path = Split-Path $path
$segments = @( $segment )
while ($segment -ne $path -and $path -ne "") {
$segment = Split-Path -Leaf $path
function Enumerable(arr) {
this.toArray = function () {
return arr
}
this.filter = function (fn) {
return new Enumerable(arr.filter(fn))
}
this.map = function (fn) {
@jennings
jennings / software-lifecycle-services.md
Last active April 26, 2017 17:06
Software Lifecycle Services
@jennings
jennings / README.md
Last active June 30, 2017 06:42
Function currying in JavaScript

A simple function for allowing partial function application in JavaScript.

function foo(a, b, c) {
    return [a, b, c]
}

var bar = foo.curry(1, 2)
bar(3)                      // => [1, 2, 3]
@jennings
jennings / jspretty.cmd
Created January 19, 2017 22:20
Reads JSON from STDIN, formats it, and prints it to STDOUT.
@echo off
node "%~dp0\jspretty.js"
@jennings
jennings / words.md
Last active October 25, 2016 23:20

High availability

Process

  • Mirroring
  • Replication

Components

  • Principal / Replica