Skip to content

Instantly share code, notes, and snippets.

View regexident's full-sized avatar

Vincent Esche regexident

View GitHub Profile
@steipete
steipete / gist:3959770
Created October 26, 2012 16:32
Macro Helpers for atomic read/write of properties.
// Atomic getting/setting of properties.
// See http://www.opensource.apple.com/source/objc4/objc4-371.2/runtime/Accessors.subproj/objc-accessors.h
extern void objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id newValue, BOOL atomic, BOOL shouldCopy);
extern id objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, BOOL atomic);
extern void objc_copyStruct(void *dest, const void *src, ptrdiff_t size, BOOL atomic, BOOL hasStrong);
#define PSPDFAtomicRetainedSetToFrom(dest, source) objc_setProperty(self, _cmd, (ptrdiff_t)(&dest) - (ptrdiff_t)(self), source, YES, NO)
#define PSPDFAtomicCopiedSetToFrom(dest, source) objc_setProperty(self, _cmd, (ptrdiff_t)(&dest) - (ptrdiff_t)(self), source, YES, YES)
#define PSPDFAtomicAutoreleasedGet(source) objc_getProperty(self, _cmd, (ptrdiff_t)(&source) - (ptrdiff_t)(self), YES)
#define PSPDFAtomicStructToFrom(dest, source) objc_copyStruct(&dest, &source, sizeof(__typeof__(source)), YES, NO)
require "./compiler/crystal/**"
while line = gets
compiler = Crystal::Compiler.new
program = Crystal::Program.new
program.target_machine = compiler.target_machine
prelude = program.normalize(Crystal::Require.new("prelude"))
// Created by Alex Gordon on 11/02/2013.
#import <Foundation/Foundation.h>
#pragma mark Objects
static BOOL respondsTo(id x, SEL s) {
if (!x || !s)
return NO;
return [x respondsToSelector:s];
@odrobnik
odrobnik / gist:5405993
Created April 17, 2013 17:01
highlight string inside attributed string
- (NSAttributedString *)attributedStringWithString:(NSString *)string highlightedwithOccurencesOfString:(NSString *)stringToHighlight inColor:(DTColor *)color
{
// build an attributed string to start with
// font
DTCoreTextFontDescriptor *fontDesc = [[DTCoreTextFontDescriptor alloc] init];
fontDesc.fontFamily = @"Helvetica";
fontDesc.pointSize = 20;
// paragraph style
extern crate ketos;
use ketos::{Interpreter, FromValue};
macro_rules! ketos_mod {
(
mod $name:ident {
$( $inner:tt )*
}
) => {
mod $name {
@thequux
thequux / README.md
Last active May 31, 2016 22:35
Multirust-compatible racer wrapper

This wrapper automatically sets the RUST_SRC_DIRECTORY environment variable for whatever rust compiler is currently active, automatically creating a new checkout whenever necessary. This should be compatible with all of the multirust-alike tools, but it has only been tested with rustup.rs

Installation

Simply place this somewhere on your path before the main racer binary and set the execute bit.

Uninstallation

@Kr1sso
Kr1sso / gist:4244369
Created December 9, 2012 11:31
Enum debugging automation for Objective C, eg. with a TextExpander snippet
#!/usr/bin/ruby
def NSStringFromEnum(input)
inputArray = input.lines.collect
typeNameLine = inputArray[-1]
typeName = typeNameLine.match(/(\w+);/)[1]
output = "NSString* NSStringFrom#{typeName}(#{typeName} value) {\n switch (value) {\n";
constantLines = inputArray[1..-2]
@DevAndArtist
DevAndArtist / guardedAreaLayoutGuide.md
Created September 13, 2017 20:47
A layout guide for iOS 10 that is very similar to the `safeAreaLayoutGuide` from iOS 11.

A layout guide for iOS 10 that is very similar to the safeAreaLayoutGuide from iOS 11.

extension UIView {
	///
	private final class LayoutGuide : UILayoutGuide {}
	
	///
	var guardedAreaLayoutGuide: UILayoutGuide {
		if #available(iOS 11, *) {
/*:
This is an implementation of Algorithm W, as found in [Principal Types for functional programs](http://web.cs.wpi.edu/~cs4536/c12/milner-damas_principal_types.pdf).
We'll start by defining literals and expressions:
*/
enum Literal {
case string(String)
case int(Int)
@cmdelatorre
cmdelatorre / id3.py
Last active February 22, 2018 16:03
Desicion tree classifier (ID3) algortihm
"""
http://en.wikipedia.org/wiki/ID3_algorithm
http://www.cise.ufl.edu/~ddd/cap6635/Fall-97/Short-papers/2.htm
"""
from collections import namedtuple, Counter, defaultdict
from math import log2