Skip to content

Instantly share code, notes, and snippets.

View cdaven's full-sized avatar

Christian Davén cdaven

View GitHub Profile
@cdaven
cdaven / log2header.php
Last active December 15, 2015 00:09
A small PHP function to log a message to the HTTP header(s) X-Log-Message.
function __log2header($message)
{
if (headers_sent())
{
return false;
}
// Escape newline (not allowed in headers)
$message = str_replace("\n", "\\n", $message);
@cdaven
cdaven / responsive.js
Created April 12, 2013 09:55
Simple boilerplate to do Javascript responsive web design (requires jQuery)
var reflowDocument = function () {
var viewportWidth = jQuery(window).width();
// do stuff here
};
jQuery(document).ready(function($) {
var reflowTimer = null;
$(window).on('resize', function () {
@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)];
}
@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());
}

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 / 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
@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 / 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 / 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 / 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();