Skip to content

Instantly share code, notes, and snippets.

View tuliofaria's full-sized avatar

Tulio Faria tuliofaria

View GitHub Profile
@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)
@tuliofaria
tuliofaria / crypt.js
Created December 8, 2017 14:28
Crypt e Decrypt com Node
const crypto = require('crypto')
const alg = 'aes-256-ctr'
const pwd = 'abcdabcd'
function crypt(text){
const cipher = crypto.createCipher(alg, pwd)
const crypted = cipher.update(text, 'utf8', 'hex')
return crypted
}
function decrypt(text){
@tuliofaria
tuliofaria / db.json
Created September 8, 2017 23:17
Servidor REST simples em PHP (Como foi construído em: https://www.youtube.com/watch?v=7s5_TmBqZR8 e em https://www.devpleno.com )
{"series":[{"name":"how i met your mother","id":"1504912239"}],"genres":[]}
@tuliofaria
tuliofaria / exercicio1.js
Created July 19, 2017 02:33
Exercicio 1
// teste
function findExemplo(){
new Promise(function(reject, resolve){
UserDataF.find({percent:0.1}, {_id:0, dmpp120:1}, function (err, data){
if(err){
reject(err)
}else{
resolve(data)
}
})
})
// Veja mais em: https://www.youtube.com/watch?v=voV5OBCqlVs
function cycleLen(n){
let steps = 1
while(n !== 1){
if ( n % 2 === 0){
n = n / 2
}else{
n = 3 * n + 1
}
@tuliofaria
tuliofaria / App.js
Last active January 16, 2017 18:41
Toptal Blog Posting about React testing with Enzyme and Jest
import React, { Component } from 'react'
import './App.css'
import NewMessage from './NewMessage'
import Messages from './Messages'
class App extends Component {
constructor(props){
super(props)
this.addNewMessage = this.addNewMessage.bind(this)
@tuliofaria
tuliofaria / 01-componente-basico-es6.js
Last active January 13, 2017 12:13
Colinha - ReactJS
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
class Componente extends Component {
render(){
return(<p>Olá devPleno!</p>)
}
}
ReactDOM.render(
@tuliofaria
tuliofaria / calc.php
Created July 29, 2016 04:13
Uma forma de evitar que usuários maliciosos fiquem "chutando" ids autoincrement na URL do seu site
Lembrar de trocar o "asdf" pelo mesmo valor que você colocou no index.php
Lembre-se isso não tira a responsabilidade de verificar se o id existe, se há permissão de acesso e etc. É só uma forma de reduzir um pouco da força bruta e do consumo de recursos desnecessários que isso pode gerar.
<?php
$id = $_GET["id"];
if($_GET["check"]!=sha1($id."asdf")){
echo "id não bate";
exit;
}