Skip to content

Instantly share code, notes, and snippets.

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

Luis Felipe Zaguini zaguiini

🏠
Working from home
View GitHub Profile
@zaguiini
zaguiini / CodigoMunicipioIBGE.json
Created July 5, 2017 14:18
JSON que mapeia de cidade/estado para código do município no IBGE. Os dados são do CENSO de 2010. É muito útil em implementações de webservices financeiros e/ou estatais.
{"PATOS DE MINAS/MG": 3148004, "JO\u00c3O PESSOA/PB": 2507507, "CALDAZINHA/GO": 5204557, "EUG\u00caNIO DE CASTRO/RS": 4307831, "S\u00c3O LUIZ GONZAGA/RS": 4318903, "ITACAMBIRA/MG": 3132008, "S\u00c3O JO\u00c3O EVANGELISTA/MG": 3162807, "RIO DOS \u00cdNDIOS/RS": 4315552, "ACARI/RN": 2400109, "NORMANDIA/RR": 1400407, "CENTRAL DO MARANH\u00c3O/MA": 2103125, "S\u00c3O LU\u00cdS/MA": 2111300, "LAGOA/PB": 2508109, "HELIODORA/MG": 3129202, "SOBRAL/CE": 2312908, "S\u00c3O JO\u00c3O DO ORIENTE/MG": 3162609, "AURORA/SC": 4201901, "S\u00c3O JOS\u00c9 DO HORT\u00caNCIO/RS": 4318481, "BARRA DO BUGRES/MT": 5101704, "S\u00c3O JO\u00c3O DA PONTA/PA": 1507466, "MESSIAS TARGINO/RN": 2407609, "ARA\u00c7U/GO": 5201603, "SALTINHO/SP": 3545159, "PIRAQUARA/PR": 4119509, "MATOS COSTA/SC": 4210704, "SALTINHO/SC": 4215356, "SEBERI/RS": 4320206, "CL\u00c1UDIA/MT": 5103056, "CURU\u00c7\u00c1/PA": 1502905, "S\u00c3O BERNARDO/MA": 2110609, "PALMEIRA DAS MISS\u00d5ES/RS": 4313706, "SANTA CRUZ DA VIT\u00d3RIA/BA": 2927804, "MORROS/MA": 2107
@zaguiini
zaguiini / score.js
Last active December 6, 2017 23:43
A test-proved, one-liner function that returns "red" if the input number is below or equal 300, "yellow" if it is below or equal 700, or "green" if it is above 700. From 0 to 1000.
// a test-proved, one-liner function that returns:
// "red" if the input number is below or equal 300,
// "yellow" if it is below or equal 700, or
// "green" if it is above 700.
// from 0 to 1000.
const getScoreColor = s => (s === undefined || s === null || s.toString() !== '0' && !parseInt(s) || +s < 0 || +s > 1000) && new Error('invalid input') || +s <= 300 && 'red' || +s <= 700 && 'yellow' || 'green'
// make sure you have jest installed globally.
test('it should throw an invalid input error', () => {
expect(getScoreColor(true)).toEqual(Error('invalid input'))
import { PureComponent } from 'react'
import { Platform, WebView as WebViewAndroid } from 'react-native'
import WebViewIOS from 'react-native-wkwebview-reborn'
const webviewRef = 'webview'
...
class App extends PureComponent {
...
...
handleNavigationStateChange({ url }) {
...
if(Platform.OS === 'ios') {
this.refs[webviewRef].evaluateJavaScript('var isNative = "ios"')
} else {
this.refs[webviewRef].injectJavaScript('var isNative = "android"')
}
...
window.onMessage = function(event) {
// now you'll follow with your callback
}
facebookLoginClicked() {
// how to post a message
switch(window.isNative) {
case 'android':
...
is(type, { nativeEvent, body }) {
return body === type || (nativeEvent && nativeEvent.data === type)
}
handleMessage(args) {
if(this.is('facebookLogin', args)) {
console.log('calling native facebook login')
}
import React, { PureComponent } from 'react'
import { StyleSheet, Platform, WebView } from 'react-native'
import WebViewIOS from 'react-native-wkwebview-reborn'
import { LoginManager, GraphRequest, GraphRequestManager } from 'react-native-fbsdk'
const
webviewRef = 'WEBVIEW',
styles = StyleSheet.create({
webview: {
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0]
if (d.getElementById(id)) {return}
js = d.createElement(s); js.id = id
js.src = "//connect.facebook.net/en_US/sdk.js"
fjs.parentNode.insertBefore(js, fjs)
}(document, 'script', 'facebook-jssdk'))
window.fbAsyncInit = function() {
FB.init({
@zaguiini
zaguiini / generate_jwt.py
Last active February 16, 2018 02:04
A simple JWT generation snippet
import jwt
from time import time # para geracao da timestamp
secret = 'minha_super_chave_imprevisivel'
user_id = 123
payload = {
'uid': user_id,
'exp': int(time()) + 3600 # queremos que o token seja valido por uma hora
@zaguiini
zaguiini / verify_jwt.py
Last active February 16, 2018 02:31
A simple JWT verification snippet
import jwt
secret = 'minha_super_chave_imprevisivel'
meu_jwt = request['headers']['authorization']
try:
informacoes = jwt.decode(meu_jwt, secret, algorithm='HS256')
except ExpiredSignatureError:
print('Seu token esta expirado!')