Skip to content

Instantly share code, notes, and snippets.

View nilium's full-sized avatar
🍉
internal screaming intensifies

Noel nilium

🍉
internal screaming intensifies
View GitHub Profile
@nilium
nilium / parse.hh
Created June 9, 2014 07:43
Basic iterator functions for parsing stuff -- e.g., accept a run of things, accept a sequence of things, accept a single character, accept while/if a given predicate is true/false, and so on and so forth. Depends on libsnow-common's option.hh.
/*
* Copyright Noel Cower 2014.
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef __PARSE_HH__
#define __PARSE_HH__
@nilium
nilium / function_info.hh
Last active August 29, 2015 14:02
Uhhh templates for function info because I HAD A VERY GOOD REASON FOR THIS.
template <typename T, typename Q>
struct function_ptr_type_t__
{
};
template <typename T>
struct function_ptr_type_t__<T, std::false_type>
{
using type = decltype(&T::operator());
@nilium
nilium / SpacedTabCompletion.py
Created June 14, 2014 09:46
Sublime Text 3 plugin to always insert spaces for indentation if there is any non-whitespace character preceding the caret.
import sublime, sublime_plugin
from sublime import Region
def column_for(view, region):
return view.rowcol(region.begin())[1]
def next_indentation(col, tab_size):
size_delta = col % tab_size
return ' ' * (tab_size - size_delta)
@nilium
nilium / huffblock
Created June 20, 2014 23:34
Filter to block everything but the article title and body on Huffington Post.
||facebook.com/plugins/$third-party,media,subdocument,object,image,script,stylesheet,xmlhttprequest,popup
||facebook.com
www.huffingtonpost.com##SECTION[class="rail"]
www.huffingtonpost.com##SECTION[id="carousel"]
www.huffingtonpost.com##NAV[class="main group"]
www.huffingtonpost.com##SECTION[class="rail"]
www.huffingtonpost.com##SECTION[class="rail fix"]
www.huffingtonpost.com##SECTION[class="header"]
www.huffingtonpost.com##SECTION[class="rail pin"]
www.huffingtonpost.com##IFRAME[class="fb_ltr"]
@nilium
nilium / defer.hh
Last active August 29, 2015 14:03
#pragma once
#include <memory>
template <typename FN>
class deferred_t
{
std::unique_ptr<FN> _block;
@nilium
nilium / glob.go
Last active August 29, 2015 14:04
package main
import (
"errors"
"fmt"
"strconv"
"strings"
"unicode/utf8"
)
@nilium
nilium / crash.swift
Last active August 29, 2015 14:04
Crashing Swift by providing a default value for a closure argument.
import Foundation
func first<S: Sequence, T where T == S.GeneratorType.Element>(seq: S, pred: (T) -> Bool = {(_) in true}) -> T? {
for x: T in seq {
if pred(x) {
return x
}
}
return nil
}
@nilium
nilium / Aux.swift
Created July 29, 2014 09:06
Function to get a list of properties for any object in Swift.
import Foundation
/// Gets a list of properties' names held by the object.
func getPropertyList(obj: AnyObject) -> [String]? {
let klass: AnyClass = object_getClass(obj)
var count: UInt32 = 0
let list = class_copyPropertyList(klass, &count)
if list == nil {
import Cocoa
let baseFoo = NSObject()
let baseBar = NSObject()
weak var weakFoo: NSObject? = baseFoo
weak var weakBar: NSObject? = baseBar
let autoFoo: NSObject! = weakFoo
#!bash
# Set to 0 to enable Mercurial prompts. Disabled because Mercurial is slow.
export DISABLE_HG_PROMPT=1
function n__get-vcs-relpath {
local P=''
P="$(git rev-parse --show-toplevel 2> /dev/null)"
if [[ -z "$P" ]] ; then