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 / QKVOForwarding.h
Created January 31, 2014 02:31
Weird idea for converting KVO changes to messages specific to the key-path. Not at all an optimal idea.
#ifndef __guard_QKVOForwarding_h__
#define __guard_QKVOForwarding_h__
#import <Foundation/Foundation.h>
@interface NSObject (QKVOForwarding)
+ (NSUInteger)maxCachedSelectorCountForForwarding;
@nilium
nilium / banner_comment.py
Created February 1, 2014 09:16
Sublime Text plugin that wraps a selection in a comment banner. It is slightly weird and definitely poorly written, but it works.
import sublime, sublime_plugin
from math import ceil
def banner_comment_width(max_content_length, min_width, padding, wall_padding, comment):
width = (
max_content_length
+ (padding * 2)
+ (wall_padding * 2)
+ len(comment[0]) + len(comment[1])
)
class BlockIterator
def initialize(args, &block)
@block = block
@args = args
end
def each
if block_given?
begin
while true ; yield @block[*@args] ; end
class Lexer
include Enumerable
def self.const_set(sym, obj) const_set(sym, obj.freeze) end
class Error < ::Exception ; end
# Token = Struct.new(:kind, :value, :position, :line, :column, :__mark)
class Token
@nilium
nilium / sign.sh
Last active August 29, 2015 13:56
#!/bin/sh
#
# sign.sh -- signing utility for Android APKs
# Made by Noel Cower. This file is public domain, or at least I'm not
# going to care what you do with it.
#
RED=''
GREEN=''
YELLOW=''
@nilium
nilium / box.cc
Last active August 29, 2015 13:56
#include <memory>
#include <type_traits>
#include <iostream>
class boxed_t
{
public:
virtual ~boxed_t() = 0;
virtual int type_id() const = 0;
};
@nilium
nilium / keypath.rb
Last active August 29, 2015 13:56
Fun little key path thing for Ruby.
#
# Key path constructor object. Builds up a key path for most instance methods
# called against itself.
#
class KeyPathCtor
def self.forwarding_method(name, old_name = nil)
old_name ||= name
define_method(name, -> (*args) do
if args.empty?
@nilium
nilium / go
Last active August 29, 2015 13:56
Utility to scan ascendant directories for .go-root files, add those directories to the GOPATH, then forward arguments to the next go command in the PATH.
#!/bin/sh
# Puts any directory with a .go-root file into the GOPATH then launches go.
__gopath_for_dir__() {
test_goroot="$1/.go-root"
if [[ -f "$test_goroot" ]] ; then
echo "${2:+$2:}$1"
else
echo "$2"
@nilium
nilium / pathto
Last active August 29, 2015 13:56
#!/usr/bin/env ruby -w
# Copyright 2014 Noel Cower
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@nilium
nilium / max.scala
Created February 28, 2014 01:48 — forked from anonymous/gist:9263513
def max(list: List[Int]): Int = list match {
case Nil => throw new NoSuchElementException
case List(x) => x
case x +: tail =>
val rhs = max(tail)
if (x >= rhs) x else rhs
}