Skip to content

Instantly share code, notes, and snippets.

View tiagobbraga's full-sized avatar

Tiago Braga tiagobbraga

View GitHub Profile
@tiagobbraga
tiagobbraga / Executar Testes RestKit
Created March 7, 2013 12:39
Antes de executar os testes do RestKit, executar esses comandos.
rvm gemset create RestKit
git submodule update --init --recursive
@tiagobbraga
tiagobbraga / gist:5110874
Created March 7, 2013 19:14
Observar modificações no elemento
$("#someDiv").bind("DOMSubtreeModified", function() {
alert("tree changed");
});
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
#define IS_IPHONE_4 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 480.0f)
// UIBarButtonItem+Custom.h
// Created by Jason Larsen on 6/21/12.
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (Custom)
- (void)customViewButtonWithImage:(NSString *)imageName target:(id)target action:(SEL)selector;
@end
@tiagobbraga
tiagobbraga / gist:5434895
Created April 22, 2013 13:32
iTunes Integration
// iOS5 Only
- (void) setMediaInfo {
NSMutableDictionary * dict = [[NSMutableDictionary alloc] init];
NSString * imName = @"imagetest.png"; // Artwork image
[dict setObject:NSLocalizedString(@"My Music", @"") forKey:MPMediaItemPropertyTitle];
[dict setObject:NSLocalizedString(@"Myself Artist", @"") forKey:MPMediaItemPropertyArtist];
MPMediaItemArtwork * mArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:imName]];
[dict setObject:mArt forKey:MPMediaItemPropertyArtwork];
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil;
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:dict];
// articles per page
var limit = 10;
// pagination middleware function sets some
// local view variables that any view can use
function pagination(req, res, next) {
var page = parseInt(req.params.page) || 1,
num = page * limit;
db.articles.count(function(err, total) {
res.local("total", total);
@tiagobbraga
tiagobbraga / gist:5737178
Last active December 18, 2015 05:59
fetch contacts io6
- (void)fetchContacts:(void (^)(NSArray *contacts))success failure:(void (^)(NSError *error))failure {
if (ABAddressBookRequestAccessWithCompletion) {
// on iOS 6
CFErrorRef err;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &err);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
// ABAddressBook doesn't gaurantee execution of this block on main thread, but we want our callbacks to be
dispatch_async(dispatch_get_main_queue(), ^{
if (!granted) {
var mongoose = require('mongoose');
mongoose.connect('localhost/test');
var Schema = mongoose.Schema;
var AlbumSchema = new Schema({
artist: { type: Schema.Types.ObjectId, ref: 'Artist' },
name: String,
year: Number,

Requirements:

If you're on OSX you're probably best off using Homebrew to install this stuff:

$ brew install node mongodb

Usage:

resetForm = (form) ->
frm_elements = form.elements
for element in frm_elements
field_type = element.type.toLowerCase();
switch field_type
when "text", "textarea", "hidden" then element.value = ""
when "radio", "checkbox" then element.checked = false
when "select-one", "select-multi" then element.selectedIndex = -1
else element.innerHTML = "";