Skip to content

Instantly share code, notes, and snippets.

@jchavarri
jchavarri / gist:5135277
Created March 11, 2013 16:00
iOS preprocessor constants
#define DOCUMENTS_PATH [NSHomeDirectory() stringByAppendingString:@"/Documents/"]
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
@jchavarri
jchavarri / UIShadowButton.h
Last active December 14, 2015 20:49
UIShadowButton - A button that moves and changes its shadow when it gets pressed.
//
// UIShadowButton.h
//
// Created by Javier Chavarri on 12/03/13.
//
#import <UIKit/UIKit.h>
@interface UIShadowButton : UIButton
@jchavarri
jchavarri / iOS - FontRetrieve
Created March 16, 2013 15:48
Retrieve fonts installed on iOS, both family name and font name
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
for (indFont=0; indFont<[fontNames count]; ++indFont)
@jchavarri
jchavarri / UIView+EasyFrame.h
Created February 10, 2014 09:40
UIView+EasyFrame
#import <UIKit/UIKit.h>
@interface UIView (EasyFrame)
@property (nonatomic) CGFloat left;
@property (nonatomic) CGFloat top;
@property (nonatomic) CGFloat right;
@property (nonatomic) CGFloat bottom;
@property (nonatomic) CGFloat width;
@jchavarri
jchavarri / app.coffee
Created January 18, 2016 23:56 — forked from jemgold/app.coffee
class-based Framer prototypes
# An example with classes building components.
# This stuff is a little fiddly to get set up,
# but once it's working it's great - you can just
# add new instances of the components, and each
# components holds references to all of its
# children. You can set defaults & states for each
# component separately.
#
# (try clicking on the post author, and then on each
# of the comments on a post)
# Define the model. All views will listen to this and update themselves, and will only have to deal with this model, instead of dealing with other views
# Extend BaseClass so we can use the on/emit bindings
class Model extends Framer.BaseClass
# Define properties that we want to observe like this so we can call `.index =` instead of .setIndex, though that works too
@define "index",
get: ()-> @_index || 0
set: (i) ->
@_index = i
# Emit the change so other things can listen to it (probably the views)
@emit "change:index"
@jchavarri
jchavarri / ES6 Class creation
Created April 4, 2016 22:53
Some tests to play with ES6 classes
// 22: class - creation
// To do: make all tests pass, leave the assert lines unchanged!
describe('class creation', () => {
it('is as simple as `class XXX {}`', function() {
class TestClass {}
const instance = new TestClass();
assert.equal(typeof instance, 'object');
@jchavarri
jchavarri / git-prune-orphan-local.sh
Created June 21, 2017 22:19
Prune local branches no longer on remote
git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d
@jchavarri
jchavarri / machine.re
Created September 21, 2017 21:39
Triggers a bad error parsing
type token =
| OpenParen
| CloseParen
| Number string
| String string;
type state =
| Init
| ParsingNumber
| ParsingString;
@jchavarri
jchavarri / beatles.re
Last active September 27, 2017 22:03
Reason: simple variant type
type beatle =
| John
| Paul
| George
| Ringo;
let drummer = Ringo;