Skip to content

Instantly share code, notes, and snippets.

@neoneye
neoneye / PostgresStORM+PickNextId.swift
Last active October 19, 2017 19:35
There can be gaps in the id column. This ensures that the id column is set to the max value
import PostgresStORM
extension PostgresStORM {
/// Set Next ID Value to MAX ID
///
/// This is a workaround for issue [ISS-546](http://jira.perfect.org:8080/browse/ISS-546)
///
/// When inserting new rows then I'm getting errors like this:
///
/// ERROR: duplicate key value violates unique constraint "president_key"
@neoneye
neoneye / qemu_osx_rpi_raspbian_jessie.sh
Created June 19, 2017 20:59 — forked from hfreire/qemu_osx_rpi_raspbian_jessie.sh
How to emulate a Raspberry Pi (Raspbian Jessie) on Mac OSX (El Capitan)
# Install QEMU OSX port with ARM support
sudo port install qemu +target_arm
export QEMU=$(which qemu-system-arm)
# Dowload kernel and export location
curl -OL \
https://github.com/dhruvvyas90/qemu-rpi-kernel/blob/master/kernel-qemu-4.1.7-jessie
export RPI_KERNEL=./kernel-qemu-4.1.7-jessie
# Download filesystem and export location
@neoneye
neoneye / demo.swift
Created November 28, 2016 13:22
Extract regex matches
extension String {
func matchingStrings(regex: String) -> [[String]] {
guard let regex = try? NSRegularExpression(pattern: regex, options: []) else { return [] }
let nsString = self as NSString
let results = regex.matches(in: self, options: [], range: NSMakeRange(0, nsString.length))
return results.map { result in
(0..<result.numberOfRanges).map { result.rangeAt($0).location != NSNotFound
? nsString.substring(with: result.rangeAt($0))
: ""
}
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
@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;
}
@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 / 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 {
import UIKit
import Forbind
import ForbindExtensions
class RemoteImageView: UIImageView {
private(set) var URL: NSURL?
private var imagePromise: Promise<Result<UIImage>>?
init() {
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"
@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>