Skip to content

Instantly share code, notes, and snippets.

View trfiladelfo's full-sized avatar

Thiago Filadelfo trfiladelfo

View GitHub Profile
@trfiladelfo
trfiladelfo / errors.m
Created July 26, 2016 18:54 — forked from benvium/errors.m
The correct way to use NSError objects in your Objective-C Code
// A function that returns an object or nil if there's an error.
- (NSObject*) doSomethingComplexAndReturnObject:(NSString*) input error:(NSError**) error {
// do some work..
BOOL itWorked = YES;
if (itWorked) {
return [[NSObject alloc] init]; // Do better memory management than this please.
} else {
*error = [NSError errorWithDomain:@"com.mycompany.myapp" code:14 userInfo:[NSDictionary dictionaryWithObject:@"My error message" forKey:NSLocalizedDescriptionKey]];
@trfiladelfo
trfiladelfo / Example.swift
Created August 14, 2016 19:00 — forked from IanKeen/Example.swift
Small utility methods to simplify dealing with Reusable items i.e. table/collection view cells
//`UITableViewCell` and `UICollectionViewCell` are `Reusable` by defaut
//Use the extension method to dequeue an instance of the appropriate `Reusable`
class MyVC: UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
tableView
.registerReusable(FooCell.self)
.registerReusable(BarCell.self)
}
@trfiladelfo
trfiladelfo / __main__.py
Created August 16, 2016 18:49 — forked from drgarcia1986/__main__.py
Example of OAuth2 autentication server with Client Credentials grant (using python-oauth2 and tornado)
# !/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Diego Garcia'
import tornado.web
import tornado.ioloop
import oauth2.tokengenerator
import oauth2.grant
import oauth2.store.redisdb
import oauth2.store.mongodb
@trfiladelfo
trfiladelfo / tornado_github_auth.py
Created August 19, 2016 21:22 — forked from FZambia/tornado_github_auth.py
tornado github oauth
# coding: utf-8
#
# Copyright (c) Alexandr Emelin. BSD license.
# All rights reserved.
#
"""
class GithubAuthHandler(BaseHandler, auth.GithubMixin):
x_site_token = 'application'
@trfiladelfo
trfiladelfo / git.css
Created August 20, 2016 23:09 — forked from neilgee/git.css
Git Command Line Reference - Notes and reminders on set up and commands
/*
* Set up your Git configuration
*/
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git config --global core.editor "nano"
@trfiladelfo
trfiladelfo / aes-cbc.py
Created October 10, 2017 20:04 — forked from lopes/aes-cbc.py
Simple Python example of AES in CBC mode.
from hashlib import md5
from base64 import b64decode
from base64 import b64encode
from Crypto import Random
from Crypto.Cipher import AES
# Padding for the input string --not
# related to encryption itself.
BLOCK_SIZE = 16 # Bytes
@trfiladelfo
trfiladelfo / aes_example_in_python.py
Created October 10, 2017 20:04 — forked from dokenzy/aes_example_in_python.py
AES Encrytion Example in Python
#-*- coding: utf-8 -*-
# Python 3.4
# author: http://blog.dokenzy.com/
# date: 2015. 4. 8
# References
# http://www.imcore.net/encrypt-decrypt-aes256-c-objective-ios-iphone-ipad-php-java-android-perl-javascript/
# http://stackoverflow.com/questions/12562021/aes-decryption-padding-with-pkcs5-python
# http://stackoverflow.com/questions/12524994/encrypt-decrypt-using-pycrypto-aes-256
@trfiladelfo
trfiladelfo / aes-ecb.py
Created October 10, 2017 20:12 — forked from lopes/aes-ecb.py
Simple Python example of AES in ECB mode.
from hashlib import md5
from base64 import b64decode
from base64 import b64encode
from Crypto.Cipher import AES
# Padding for the input string --not
# related to encryption itself.
BLOCK_SIZE = 16 # Bytes
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * \
@trfiladelfo
trfiladelfo / __main__.py
Created October 11, 2017 03:38 — forked from anonymous/__main__.py
SOAP, zeep
from zeep import Client, helpers
client = Client('https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl')
resp = client.service.consultaCEP('06694720')
resp = helpers.serialize_object(resp)
resp = {k: resp[k] for k in resp}
print(resp)
client = Client('http://www.webservicex.com/globalweather.asmx?wsdl')
resp = client.service.GetCitiesByCountry('New York')
@trfiladelfo
trfiladelfo / gist:e81e11749a5ec19adbf77860ecb49621
Created November 12, 2017 20:43 — forked from simonw/gist:7000493
How to use custom Python JSON serializers and deserializers to automatically roundtrip complex types.
import json, datetime
class RoundTripEncoder(json.JSONEncoder):
DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"
def default(self, obj):
if isinstance(obj, datetime.datetime):
return {
"_type": "datetime",
"value": obj.strftime("%s %s" % (