Skip to content

Instantly share code, notes, and snippets.

View cdaven's full-sized avatar

Christian Davén cdaven

View GitHub Profile
import matplotlib.pyplot as plt
import random
import numpy as np
from scipy.optimize import curve_fit
INITIAL_BUGS = 50
LINES_OF_CODE = 1000
TESTERS = 5
RUNS = 10
@cdaven
cdaven / DeadlockController.cs
Created February 9, 2022 14:03
ASP.NET async Deadlock Example
using System.Threading.Tasks;
using System.Web.Mvc;
namespace DeadlockExperiment.Controllers
{
public class DeadlockController : Controller
{
public ActionResult Index()
{
AsyncMethod().Wait(); // Deadlock!
@cdaven
cdaven / AsyncDeadlock.cs
Last active February 9, 2022 12:13
Example of synchronous blocking causing deadlock
async Task PauseAsync()
{
// Normal asynchronous method call
await Task.Delay(1000);
}
void Pause()
{
// Synchronous method blocking on asynchronous method
PauseAsync().Wait();
@cdaven
cdaven / AdventOfCode2020_Day1.fs
Last active December 2, 2020 07:43
Advent of Code 2020, Day1 (F#)
open System
let readLines filePath = System.IO.File.ReadAllLines(filePath)
let day1 =
printfn "** Day 1 **"
// Läs in alla rader till ett set av heltal
let entries = readLines "data/1.txt" |> Set.ofArray |> Set.map Int32.Parse
// Ta fram alla "2020-kompis-par" för varje tal
@cdaven
cdaven / MicroBreak.ahk
Last active August 13, 2020 05:09
Micro Break Reminder for Windows using AutoHotkey
#Persistent
; Run ShowBreakMessage every 30 minutes
SetTimer, ShowBreakMessage, 1800000
Return
ShowBreakMessage:
if (A_TimeIdlePhysical > 900000)
{
; Idle more than 15 minutes - no reminder
@cdaven
cdaven / Spacemacs on Windows 10.md
Last active May 14, 2024 08:48
Setting up Spacemacs on Windows 10

Install Emacs First

Download emacs-w64 and extract somewhere, e.g. a tools or apps folder like C:\Users\<user>\tools\emacs.

Select Emacs' Home

Emacs and many other applications store its configuration in the user's "home" folder. Translated directly from the Unix world, that is %UserProfile% (C:\Users\<user>), but Windows prefers %AppData% instead (C:\Users\<user>\AppData\Roaming).

For simplicity's sake, override this by specifying the HOME environment variable explicitly. Emacs and some other applications (e.g. MinGW) lets this override the default.

@cdaven
cdaven / SetupUbuntuDevelopment.sh
Last active December 26, 2019 06:14
Setup Ubuntu Development Machine on Windows
#!/bin/bash
# Instructions for setting up a custom development machine
# on Ubuntu 18.04, distributed via Microsoft Store.
# Step 1: Install the Windows Subsystem for Linux:
# https://docs.microsoft.com/en-us/windows/wsl/install-win10
# Step 2: Install Ubuntu via Windows Store:
# https://www.microsoft.com/store/apps/9N9TNGVNDL3Q

git-flow cheat sheet

TL;DR from A successful Git branching model by Vincent Driessen.

Creating a feature branch

When starting work on a new feature, branch off from the develop branch.

$ git checkout -b myfeature develop
@cdaven
cdaven / uuid.php
Created May 22, 2013 11:11
Return a kind of UUID...
function uuid($identifier = '')
{
return sha1($identifier.microtime(true).mt_rand().php_uname());
}
@cdaven
cdaven / randomString.php
Created May 21, 2013 12:20
Generate a string of random characters
function generateRandomString($length = 10)
{
$alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
$alphabet_length = strlen($alphabet);
$randomChars = array();
for ($i = 0; $i < $length; $i++)
{
$randomChars[] = $alphabet[mt_rand(0, $alphabet_length - 1)];
}