Skip to content

Instantly share code, notes, and snippets.

View tuliofaria's full-sized avatar

Tulio Faria tuliofaria

View GitHub Profile
import styles from './styles.module.css'
const MyButton = () => {
return <button classNames={styles.myBtn}>Opa!</button>
}
export default MyButton
@tuliofaria
tuliofaria / arquivo.js
Created December 7, 2018 22:05
Trecho de código utilizado no Hands-on React-native do DevPleno
regionFrom = (lat, lon, distance) => {
distance = distance/2
const circumference = 40075
const oneDegreeOfLatitudeInMeters = 111.32 * 1000
const angularDistance = distance/circumference
const latitudeDelta = distance / oneDegreeOfLatitudeInMeters
const longitudeDelta = Math.abs(Math.atan2(
Math.sin(angularDistance)*Math.cos(lat),
Math.cos(angularDistance) - Math.sin(lat) * Math.sin(lat)))
const express = require('express')
const path = require('path')
const app = express()
const port = process.env.PORT || 3000
const mysql = require('mysql')
const connection = mysql.createConnection({
host:'127.0.0.1',
port:'8889',
user:'root',
password:'root',
const sleep = time => new Promise(resolve => setTimeout(resolve, time))
const teste = async() => {
console.log('ola')
await sleep(1000)
console.log('depois do sleep')
}
teste()

Keybase proof

I hereby claim:

  • I am tuliofaria on github.
  • I am tuliofaria (https://keybase.io/tuliofaria) on keybase.
  • I have a public key ASBtdOZxrex_iwwZ3G_u7rPDHbxZKU7cj6Chrb1MywCSXQo

To claim this, I am signing this object:

@tuliofaria
tuliofaria / index.js
Created December 22, 2017 23:09
Playing a video in Chromecast with NodeJS
const mdns = require('mdns')
const Client = require('castv2-client').Client
const DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver
const playMedia = host => {
const client = new Client()
client.connect(host, () => {
console.log('connected')
client.launch(DefaultMediaReceiver, (err, player) => {
@tuliofaria
tuliofaria / index.js
Created December 22, 2017 01:24
Discovering Chromecasts in local network
const mdns = require('mdns')
const browser = mdns.createBrowser(mdns.tcp('googlecast'))
browser.on('serviceUp', service => {
const { md, fn } = service.txtRecord
console.log(md, fn)
})
browser.on('serviceDown', service => {
const { md, fn } = service.txtRecord
console.log(md, fn)
@tuliofaria
tuliofaria / how-to.sh
Created December 15, 2017 14:55
Dumping (with mongodump) an AtlasDB
mongodump --uri "mongodb://<user>:<passwd>@<server1>:27017,<server2>:27017,<server3>:27017/<dbName>?ssl=true&replicaSet=<replicaSetName>&authSource=admin"
@tuliofaria
tuliofaria / crypt.js
Created December 11, 2017 00:05
Crypt-with-iv
const crypto = require('crypto')
const alg = 'aes-256-ctr'
const pwd = 'abcdabcdabcdabcdabcdabcdabcdabcd'
function crypt(text){
const iv = crypto.randomBytes(16)
const cipher = crypto.createCipheriv(alg, pwd, iv)
const crypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex')
return iv.toString('hex')+':'+crypted
}
@tuliofaria
tuliofaria / crypt-file.js
Created December 8, 2017 20:47
Crypt e Decrypt Files
const fs = require('fs')
const crypto = require('crypto')
const alg = 'aes-256-ctr'
const passwd = 'abcdabcd'
const read = fs.createReadStream('input.txt')
const write = fs.createWriteStream('output.txt')
const cipher = crypto.createCipher(alg, passwd)