Skip to content

Instantly share code, notes, and snippets.

View Warwolt's full-sized avatar

Rasmus Källqvist Warwolt

  • Mojang Studios
  • Stockholm
View GitHub Profile
@justintv
justintv / .bashrc
Created August 17, 2009 00:53
Display git branch in bash prompt
# If you work with git, you've probably had that nagging sensation of not knowing what branch you are on. Worry no longer!
export PS1="\\w:\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\$ "
# This will change your prompt to display not only your working directory but also your current git branch, if you have one. Pretty nifty!
# ~/code/web:beta_directory$ git checkout master
# Switched to branch "master"
# ~/code/web:master$ git checkout beta_directory
# Switched to branch "beta_directory"
@chiragchamoli
chiragchamoli / gist:3754597
Created September 20, 2012 08:09
Example of 1NF, 2NF and 3NF in plain english?

1NF is the most basic of normal forms - each cell in a table must contain only one piece of information, and there can be no duplicate rows.

2NF and 3NF are all about being dependent on the primary key. Recall that a primary key can be made up of multiple columns. As Chris said in his response:

The data depends on the key [1NF], the whole key [2NF] and nothing but the key [3NF] (so help me [Codd][1]).

2NF

Say you have a table containing courses that are taken in a certain semester, and you have the following data:

@evincarofautumn
evincarofautumn / monoid.cpp
Last active August 1, 2024 20:10
Monoids in C++
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
// In Haskell, the Monoid typeclass is parameterised by only a type. Such a
// definition requires “newtype hacks” to produce different monoids on the same
// type. This definition is parameterised by both the type and the function, and
// as such can be used to define different monoids on the same type without any
// interference.
@Cheeseness
Cheeseness / gist:8a49668d0a43278b72b2
Last active May 16, 2024 03:28
C++ SDL Fullscreen Toggle
/*
* A function for toggling windowed mode in a C++ SDL app. Fullscreen windows will appear on whichever screen the window was on.
*
* Could be used in conjunction with SDL_GetDisplayName(int displayIndex)
* and SDL_GetNumVideoDisplays(void) to programmatically force fullscreen onto a particular display
*/
void toggleWindowed()
{
//Grab the mouse so that we don't end up with unexpected movement when the dimensions/position of the window changes.
function prompt
{
# Determine if Powershell is running as Administrator
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() )
$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
$leftCharCount = 0
$middleCharCount = 0
$rightCharCount = 0
@andymatuschak
andymatuschak / States-v3.md
Last active August 16, 2025 08:46
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@jlgerber
jlgerber / CMakeLists.txt
Last active May 21, 2024 20:28
cmake - handling executable and library with same name
# Lets say we want to add a library and an executable, both with the same name.
# In this example, it is resman
add_library(resman ${src_cpps} ${src_hpps} )
target_link_libraries(resman ${Boost_LIBRARIES} ${LIBYAML} ${LIBFMT})
#
# Add resman executable
#
# We call the executable resman-bin
add_executable(resman-bin main.cpp )
@obsoke
obsoke / FYT_Rust_Notes.md
Created January 4, 2017 04:06
Fix Your Timestep Notes - Rust Style

Simple: Fixed Delta Time

let mut t: 0.0;
let dt = 1.0 / 60.0;

loop {
    update(t, dt);
    render();
@PrestonKnopp
PrestonKnopp / optional.gd
Last active September 20, 2023 21:15
Attempt at Optionals in GDScript
# optional.gd
#
# Caveat
# ------
# This only works with types inheriting from Object. Built-in types don't work
# with the call api. Built-ins can still be fetched but they cannot be operated
# on.
#
# This can be fixed by subclassing optional and adding type specific methods
# that wrap the builtin type.