Skip to content

Instantly share code, notes, and snippets.

Avatar

Stuart Carnie stuartcarnie

View GitHub Profile
@stuartcarnie
stuartcarnie / NSEvent+Publisher.swift
Last active Aug 23, 2020
Combine Publisher support for NSEvent.addLocalMonitorForEvents
View NSEvent+Publisher.swift
@available(macOS 10.15, *)
extension NSEvent {
static func publisher(scope: Publisher.Scope, matching: EventTypeMask) -> Publisher {
return Publisher(scope: scope, matching: matching)
}
public struct Publisher: Combine.Publisher {
public enum Scope {
case local, global
}
@stuartcarnie
stuartcarnie / .zshrc
Last active Aug 7, 2020
My standard .zshrc with oh-my-zsh
View .zshrc
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="juanghurtado"
@stuartcarnie
stuartcarnie / LICENSE.txt
Last active May 26, 2020
Clang API notes schema definition
View LICENSE.txt
Copyright 2020 Stuart Carnie
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
distributed under the License is distributed on an "AS IS" BASIS,
@stuartcarnie
stuartcarnie / clear-apc.php
Last active Mar 12, 2020
Self-contained php script to clear shared-memory cache in php5-fpm via command-line. In this instance it is clearing APC, but can be easily changed to clear other shared-memory caches.
View clear-apc.php
#!/usr/bin/env php
<?php
/*
Copyright 2013 Stuart Carnie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
@stuartcarnie
stuartcarnie / tmux-reverse
Created Apr 7, 2017
One-liner to ensure italics are rendered as reverse when using tmux
View tmux-reverse
mkdir $HOME/.terminfo/ && \
screen_terminfo="screen-256color" && \
infocmp "$screen_terminfo" | sed \
-e 's/^screen[^|]*|[^,]*,/screen-256color|screen with italics support,/' \
-e 's/%?%p1%t;3%/%?%p1%t;7%/' \
-e 's/smso=[^,]*,/smso=\\E[7m,/' \
-e 's/rmso=[^,]*,/rmso=\\E[27m,/' \
-e '$s/$/ sitm=\\E[3m, ritm=\\E[23m,/' > /tmp/screen.terminfo && \
tic /tmp/screen.terminfo && \
echo set -g default-terminal "screen-256color" | tee -a ~/.tmux.conf
@stuartcarnie
stuartcarnie / main.m
Created Mar 4, 2011
Demonstrates we can now support limited JIT compilation on recent versions of iOS (assuming Apple approves entitlements at some future point)
View main.m
//
// main.m
// ProtectTest
// Demonstrates newer versions of iOS now support PROT_EXEC pages, for just-in-time compilation.
//
// Must be compiled with Thumb disabled
//
// Created by Stuart Carnie on 3/4/11.
// Copyright 2011 Manomio LLC. All rights reserved.
//
@stuartcarnie
stuartcarnie / influxql.ebnf
Last active May 17, 2017
EBNF for InfluxQL
View influxql.ebnf
// queries
query ::= statement ( ";" statement )*
statement ::= alter_retention_policy_stmt |
create_continuous_query_stmt |
create_database_stmt |
create_retention_policy_stmt |
create_subscription_stmt |
create_user_stmt |
@stuartcarnie
stuartcarnie / tsm.ksy
Last active Mar 25, 2017
Kaitai Struct definition for InfluxDB .tsm files
View tsm.ksy
meta:
id: tsm
title: InfluxDB TSM file
license: MIT
file-extension: tsm
endian: be
seq:
- id: header
type: header
@stuartcarnie
stuartcarnie / json-pretty
Last active Dec 17, 2015
Script to pretty json input
View json-pretty
#!/usr/bin/env python
r"""Command-line tool to validate and pretty-print JSON
Usage::
$ echo '{"json":"obj"}' | python -m json.tool
{
"json": "obj"
}
$ echo '{ 1.2:3.4}' | python -m json.tool
@stuartcarnie
stuartcarnie / main.m
Created Sep 16, 2012
tail call with fake msgSend in Objective C
View main.m
#import <Foundation/Foundation.h>
#import <objc/message.h>
extern id fake_msgSend(id, SEL, int) __attribute__((noinline));
@interface Foo : NSObject
- (id)foo:(int)n;
@end
You can’t perform that action at this time.