Skip to content

Instantly share code, notes, and snippets.

View tiagobbraga's full-sized avatar
🏠
Working from home

Tiago Braga tiagobbraga

🏠
Working from home
View GitHub Profile
@tiagobbraga
tiagobbraga / PHPhotoLibrary+SaveImage
Last active November 27, 2019 01:48 — forked from khorbushko/PHPhotoLibrary+SaveImage
PHPhotoLibrary+SaveImage - save image with Photos Framework swift 2.3 and 3
// SWIFT 3
import UIKit
import Photos
extension PHPhotoLibrary {
// MARK: - PHPhotoLibrary+SaveImage
// MARK: - Public
func savePhoto(image:UIImage, albumName:String, completion:((PHAsset?)->())? = nil) {
@tiagobbraga
tiagobbraga / hide-iterm-dock-icon.md
Created May 27, 2017 22:22 — forked from stvhwrd/hide-iterm-dock-icon.md
Hide the iTerm dock icon on Mac OS X

On my dual-drive MacBook Pro I have remapped the eject key to F13 using Karabiner and NoEjectDelay. The eject key has been assigned as the hotkey for a guake-style visor terminal using iTerm2. Having its own hotkey precludes the need for an icon, so I prefer to hide the iTerm dock icon.

####To hide the dock icon of iTerm2 on Mac OS X:

/usr/libexec/PlistBuddy -c 'Add :LSUIElement bool true' /Applications/iTerm.app/Contents/Info.plist

####To undo the above:

@tiagobbraga
tiagobbraga / iterm2-solarized.md
Created May 27, 2017 21:51 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Meslo powerline font + [Powerlevel9k] - (macOS)

Default

Default

Powerlevel9k

Powerlevel9k

@tiagobbraga
tiagobbraga / LOGIN_THE_SAME_FORM_TWO_MODELS.md
Created September 28, 2016 20:07
Unified sign in form for multiple types of Devise users.

An application I'm working on has two different types of Devise users, but I want both types of users to be able to use the same sign in form. Devise doesn't make this easy.

You could argue that I really should have a single user type with a role attribute, but the app is far enough along that I don't want to change that early design decision. It could be changed later if more pain points are discovered.

You could also argue that I shouldn't use Devise, but it's still the de facto authentication standard for Rails applications.

In this example, you can sign in as either a User or an AdminUser. This application only has two types of user, but this example could be extended to support any number of them more gracefully.

@tiagobbraga
tiagobbraga / Steps.md
Last active July 29, 2016 21:06 — forked from Godoy/Steps.md
deploy ruby on rails 4 with capistrano nginx unicorn - ubuntu 14.04

Steps

These steps were made with Ubuntu 14.04 e ruby 2.2.2. To enjoy the ease of step-by-step, I suggest not change folders and application name - just change the server ip and git

Create user to deploy

# Server console
sudo adduser deployer
sudo gpasswd -a deployer sudo
@tiagobbraga
tiagobbraga / contact.m
Created March 10, 2016 12:37 — forked from willthink/contact.m
Using CNContactStore in Objective C to query contacts info
#import <Contacts/Contacts.h>
@implementation ContactsScan
- (void) contactScan
{
if ([CNContactStore class]) {
//ios9 or later
CNEntityType entityType = CNEntityTypeContacts;
if( [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusNotDetermined)
@tiagobbraga
tiagobbraga / Add and remove view of View Controller
Last active August 29, 2015 14:23 — forked from tomohisa/gist:2897676
Add and Remove View of ViewController
// add child view
UIViewController* controller = [self.storyboard instantiateViewControllerWithIdentifier:@"test"];
[self addChildViewController:controller];
controller.view.frame = CGRectMake(0, 44, 320, 320);
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
// remove child view
UIViewController *vc = [self.childViewControllers lastObject];
[vc willMoveToParentViewController:nil];
<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name=apple-mobile-web-app-capable content=yes>
<meta name=apple-mobile-web-app-status-bar-style content=black>
<title>Test fullscreen</title>
<style>
html, body {
margin: 0;
padding: 0;

Requirements:

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

$ brew install node mongodb

Usage:

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,