Skip to content

Instantly share code, notes, and snippets.

View mtrovilho's full-sized avatar

Marcos Trovilho mtrovilho

View GitHub Profile

Keybase proof

I hereby claim:

  • I am mtrovilho on github.
  • I am mtrovilho (https://keybase.io/mtrovilho) on keybase.
  • I have a public key whose fingerprint is ED05 8D9B 3A06 BAE9 7F10 8B96 E025 F6CB D479 563A

To claim this, I am signing this object:

@mtrovilho
mtrovilho / Aircrack Commands
Last active January 11, 2020 21:08 — forked from victorreyesh/Aircrack Commands
Cracking WPA2 / WEP Wifi / Aircrack 10 seconds guide. For Mac OSX
// Install the latest Xcode, with the Command Line Tools.
// Install Homebrew
// Install aircrack-ng:
brew install aircrack-ng
// Create the following symlink:
sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/sbin/airport
// Figure out which channel you need to sniff:
sudo airport -s
@mtrovilho
mtrovilho / FCPrivateBatteryStatus.m
Created April 5, 2016 19:23
How to get raw battery info (mAh remaining, etc.) from iOS using private APIs. For internal testing only, NOT APP STORE DISTRIBUTION!
#import <Foundation/Foundation.h>
#include <dlfcn.h>
NSDictionary *FCPrivateBatteryStatus()
{
static mach_port_t *s_kIOMasterPortDefault;
static kern_return_t (*s_IORegistryEntryCreateCFProperties)(mach_port_t entry, CFMutableDictionaryRef *properties, CFAllocatorRef allocator, UInt32 options);
static mach_port_t (*s_IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching CF_RELEASES_ARGUMENT);
static CFMutableDictionaryRef (*s_IOServiceMatching)(const char *name);
extension Character {
var uppercaseCharacter: Character {
return Character(String(self).uppercaseString)
}
var lowercaseCharacter: Character {
return Character(String(self).lowercaseString)
}
func isUppercaseCharacter() -> Bool {
extension Array {
func shuffle() -> [Element] {
var shuffledCollection = self
var remainingElements = self.count
while remainingElements > 0 {
let currentIndex = remainingElements - 1
let newIndex = Int(arc4random_uniform(UInt32(remainingElements)))
let temp = shuffledCollection[currentIndex]
{
"continents": {
"AF": "África",
"AN": "Antártica",
"AS": "Asia",
"EU": "Europa",
"NA": "América do Norte",
"OC": "Oceania",
"SA": "América do Sul"
},

Swift Don'ts

  • Don't add code cruft. Avoid parentheses around conditions in if-statements or with the return keyword. Don't add semicolons except where syntactically demanded in statements or to separate statements on the same line.
  • Don't use ALL_CAPS; use camelCase
  • Don't fight type inference. Use enumeration prefixes, self-references, and class names (with constructors) only when necessary or to clarify coding intent.
  • Don't use var when let is appropriate, especially for properties. The compiler better optimizes let statements for items whose values will not change during their lifetime. For example, Apple writes, "It is good practice to create immutable collections in all cases where the collection does not need to change. Doing so enables the Swift compiler to optimize the performance of the collections you create."
  • Don't use classes when structs will do. Use class
@mtrovilho
mtrovilho / DictionaryExtension.swift
Last active February 14, 2017 21:55
Swift Dictionary Extension
import Foundation
extension Dictionary {
func fetch(_ key: Key, defaultValue: @autoclosure () -> Value) -> Value {
return self[key] ?? defaultValue()
}
func fetch<T>(_ key: Key, castTo type: T.Type, defaultValue: @autoclosure () -> T) -> T {
return self[key] as? T ?? defaultValue()
}
@mtrovilho
mtrovilho / Preferences.sublime-settings
Created March 5, 2015 13:50
Sublime Text 2 - User Settings
{
"auto_complete_commit_on_tab": true,
"auto_complete_with_fields": true,
"bold_folder_labels": true,
"caret_style": "solid",
"close_windows_when_empty": true,
"color_scheme": "Packages/Tomorrow Color Schemes/Tomorrow-Night.tmTheme",
"create_window_at_startup": false,
"drag_text": false,
"ensure_newline_at_eof_on_save": true,
@mtrovilho
mtrovilho / mfr.swift
Last active August 29, 2015 14:10
Map, Filter, Reduce
//------------------------------------------------------------------------------
// Aula 4 - 27-11-2014 - Funcional - Map, Filter, Reduce
//------------------------------------------------------------------------------
//-- Com cenas dos proximos capitulos (Generics, Structs)
var numeros = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
//-- Sintaxe diferente
reduce(numeros, 0, +)
reduce(numeros, 1, *)