Skip to content

Instantly share code, notes, and snippets.

View neoneye's full-sized avatar

Simon Strandgaard neoneye

View GitHub Profile
@neoneye
neoneye / rakefile.rb
Created July 17, 2014 09:42
Count total number of lines in a project
def count_number_of_lines(path, suffix)
count = 0
Dir.chdir(path) do
cmd = 'find . -type f -name "*.SUFFIX" -print0 | xargs -0 cat | wc -l'
cmd.gsub!('SUFFIX', suffix)
result = `#{cmd}`
count = result.to_i
end
return count
end
@neoneye
neoneye / gist:af985fac27bc7cdc7836
Created December 18, 2014 19:18
Curiously recurring template pattern in swift is not working
// https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
class Foo <T: Any> : T {
func hello() { println("hello") }
}
class Bar {
func world() { println("world") }
}
@neoneye
neoneye / gist:cef81456451a79a10281
Created December 23, 2014 18:11
color extension
import UIKit
extension UIColor {
// usage:
// myButton.backgroundColor = UIColor.rgb(240, 10, 20)
class func rgb(red: Int, _ green: Int, _ blue: Int) -> UIColor {
return rgba(red, green, blue, 255)
}
// usage:
@neoneye
neoneye / gist:9bf2904c1d872149c656
Created September 3, 2015 19:51
How to enable crontab on Mac OS X 10.10 Yosemite
prompt> sudo touch /etc/crontab
Password: ***************
prompt>
import lldb
import re
import shlex
# This script allows Xcode to selectively ignore Obj-C exceptions
# based on any selector on the NSException instance
def getRegister(target):
if target.triple.startswith('x86_64'):
return "rdi"
import UIKit
import Forbind
import ForbindExtensions
class RemoteImageView: UIImageView {
private(set) var URL: NSURL?
private var imagePromise: Promise<Result<UIImage>>?
init() {
@neoneye
neoneye / CustomViewFromXib.swift
Created March 11, 2016 21:58
I have just ported Paul Slot's awesome "PSCustomViewFromXib" from objective C to Swift
// Inspired by Paul Slot's awesome PSCustomViewFromXib, https://github.com/PaulSolt/CustomUIView
class CustomViewFromXib: UIView {
var customView: UIView?
override init(frame: CGRect) {
super.init(frame: frame)
let className = String(self.dynamicType)
let anyObjectOrNil: AnyObject? = NSBundle.mainBundle().loadNibNamed(className, owner: self, options: nil)?.first
guard let anyObject = anyObjectOrNil else {
@neoneye
neoneye / environment.cpp
Created May 17, 2016 18:43
posix_spawn with an "environment" class
// Copyright © 2015 Simon Strandgaard. All rights reserved.
// MIT license
#include "environment.hpp"
#include <unistd.h>
#include <iostream>
#include <boost/algorithm/string/predicate.hpp>
extern char **environ;
void Environment::populateWithGlobalEnvironment() {
@neoneye
neoneye / nginx.conf
Created September 4, 2016 16:44
NGINX controls a FastCGI script
user neoneye staff;
worker_processes 1;
error_log /Library/Logs/nginx/error.log debug;
events {
worker_connections 256;
}
PROMPT> hostname
abcdef.local
PROMPT> ifconfig -a
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
inet6 ::1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1