Skip to content

Instantly share code, notes, and snippets.

View brunokrebs's full-sized avatar

Bruno Krebs brunokrebs

View GitHub Profile
app.delete('/:id', (req, res) => {
const { id } = req.params;
for (let i = 0; i < questions.length; i++) {
const question = questions[i];
if (question.id === parseInt(id)) {
questions.splice(i, 1);
return res.status(200).send();
}
}
@brunokrebs
brunokrebs / SecuredRoute.js
Created August 24, 2018 14:38
React component to secure another component.
import React from 'react';
import {Route} from 'react-router-dom';
import auth0Client from '../Auth';
function SecuredRoute({ component: Component, ...rest }) {
return (
<Route {...rest} render={(props) => {
if (!auth0Client.isAuthenticated()) return auth0Client.signIn();
return <Component {...props} />
}} />
@brunokrebs
brunokrebs / GossipService.ts
Created August 19, 2018 16:45
Playing with TypeScript Generics
class GossipService {
gossip(message: string) {
console.log(message.toLowerCase());
}
}
export default GossipService;
@brunokrebs
brunokrebs / script.js
Created April 10, 2018 18:42
Script to be ran manually. It searches for clients and centralised on pages.
let clientLinks = [].slice.call(document.getElementsByTagName('a')).filter(link => {
const {href} = link;
if (href.indexOf('manage.auth0.com') < 0) return null;
if (href.indexOf('clients') > 0) return link;
return null;
});
# issue a POST request to get a token
curl -X POST -H 'Content-Type: application/json' -d '{
username: "mario",
password: "secret"
}' http://localhost:63939/api/token
# replace xxx.yyy.zzz with the token retrieved in the previous command
JWT="xxx.yyy.zzz"
# use the token to retrieve books
@brunokrebs
brunokrebs / spread-operator.js
Created December 28, 2017 17:02
Using Spread Operator in objects and arrays.
let arr1 = ['apple', 'banana'];
let arr2 = [...arr1, 'watermelon'];
console.log(arr1);
console.log(arr2);
let obj1 = {
name: 'Bruno',
surname: 'Krebs'
}
let obj2 = {
@brunokrebs
brunokrebs / run-mysql-docker.sh
Last active September 21, 2019 18:08
Just a reminder on how to run, stop, and remove a MySQL instance on docker.
docker run --name mysql \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=my-password \
-e MYSQL_DATABASE=some-db-name \
-e MYSQL_USER=some-user \
-e MYSQL_PASSWORD=some-user-password \
-d mysql:5.7
docker stop mysql
docker rm mysql
@brunokrebs
brunokrebs / SecurityConfig.java
Created November 28, 2017 00:35
Accepting requests from any origin (use it for tests only)
package com.auth0.samples.secure;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
alias new_post="create_new_post"
function create_new_post {
# are we are on blog's root dir?
ls | grep Rakefile &> /dev/null \
&& ls | grep _posts &> /dev/null
if [ $? -gt 0 ]; then
echo "not on blog's root directory"
return 1
fi
@brunokrebs
brunokrebs / index.js
Created November 16, 2017 12:01
Accessing headers on a response after a POST request sent by axios
const axios = require('axios');
axios.post('http://localhost:8080/login', {
"username": "admin",
"password": "password"
}).then(function (response) {
console.log(response.headers.authorization);
}).catch(function (error) {
console.log(error);
});