Skip to content

Instantly share code, notes, and snippets.

View killerswan's full-sized avatar

Kevin Cantú killerswan

View GitHub Profile
@killerswan
killerswan / gist:941923
Created April 26, 2011 07:04 — forked from mneedham/gist:941892
Purely Functional Data Structures - Chris Okasaki
(* This uses the @ operator (aka List.append) which is not tail recursive *)
let suffixes list =
let rec loop l acc =
match l with
| [] -> acc
| x::xs -> loop xs (acc @ [xs]) in
loop list [list]
(* This uses an operator @+ constructed from two tail recursive methods... :P *)
@killerswan
killerswan / gist:942108
Created April 26, 2011 10:53 — forked from mneedham/gist:941867
Purely Functional Data Structures - Chris Okasaki
(* Brian McNamara's approach isn't actually that bad, unless List had an efficient append. But simplify it like so... *)
let suffixesTR3 list =
let rec loop l acc =
match l with
| [] -> acc
| _::xs -> loop xs (xs :: acc) in
List.rev (loop list [list])
@killerswan
killerswan / centered_triangle.html
Created May 3, 2011 06:26 — forked from romannurik/centered_triangle.html
A simple CSS trick to create a horizontally- or vertically-centered 'selected' callout triangle using zero images.
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 40px;
}
a {
display: inline-block;
@killerswan
killerswan / gist:1258000
Created October 2, 2011 21:40 — forked from swannodette/gist:1257981
redblacknew.cljs
(defn balance [node]
(match [node]
[( [:black [:red [:red a x b] y c] z d]
| [:black [:red a x [:red b y c]] z d]
| [:black a x [:red [:red b y c] z d]]
| [:black a x [:red b y [:red c z d]]]
)]
[:red [:black a x b] y [:black c z d]]
:else
node))
@killerswan
killerswan / gist:1625204
Created January 17, 2012 06:39 — forked from brson/gist:1625144
reserve
fn reserve(&ss: str, nn: uint) unsafe {
// start with an existing string
str::char_len(ss); std::io::println("+++A+++");
// make a vector
let vv: [u8] = unsafe::reinterpret_cast(ss);
str::char_len(ss); std::io::println("+++B+++");
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Helpers for automating the process of setting up ported Linux/UNIX
applications which were designed with expectations like being in $PATH.
@note: Basic functionality requires only the Python standard library.
Some functions and methods also require the PyWin32 package.
@note: A much more verbose "sudo for Windows" implementation (BSD-licensed)
@killerswan
killerswan / pr.md
Created August 26, 2016 12:13 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@killerswan
killerswan / git_notes.md
Created November 22, 2019 08:39 — forked from jaygooby/git_notes.md
Git, you bloody git

Remove all local tracking branches to a remote & then delete the remote

git remote prune origin && git remote rm origin

Force checkout a branch to avoid the commit or stash your changes warning

Sometimes when you want to checkout a branch, even though your current branch is clean, you'll get a failed partial checkout, because a file in your current branch will be changed by the new branch (Looking at you .xcodeproj files). As long as you know your current branch is clean and up-to-date, -f force the checkout

git checkout -f the_branch

@killerswan
killerswan / tco.py
Created April 19, 2021 05:44 — forked from sagnibak/tco.py
Implementation of a tail-call optimizing function decorator and accompanying types in Python.
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, Generic, Optional, Tuple, TypeVar, Union
ReturnType = TypeVar("ReturnType")
@dataclass
class TailCall:
args: Tuple[Any, ...] = field(default_factory=tuple)