Skip to content

Instantly share code, notes, and snippets.

View leonardofreitass's full-sized avatar

Leonardo Freitas dos Santos leonardofreitass

View GitHub Profile
@leonardofreitass
leonardofreitass / monty_hall.js
Last active February 7, 2020 13:05
Monty Hall Problem
// Amount of time to run the problem
const RUN_TIMES = 10000
const runProblem = (change) => {
// Starts with 3 doors containing nothing
const chances = ['nothing', 'nothing', 'nothing']
// Puts money behind one of the three doors randomly
chances[Math.floor(Math.random() * 3)] = 'money'
// Picks one of the doors randomly
@leonardofreitass
leonardofreitass / person.ts
Last active August 2, 2017 20:04
Person class wrote in TypeScript
class Person {
private name: string;
private age: number;
constructor(name: string, age: number){
this.name = name;
this.age = age;
}
@leonardofreitass
leonardofreitass / person.js
Last active June 9, 2018 16:56
Person class wrote in JavaScript
class Person {
constructor(name, age){
this.name = name;
this.age = age;
}
advanceAge(){
this.age++;
}
@leonardofreitass
leonardofreitass / bad_type.ts
Created August 2, 2017 18:07
Example of a bad type
(<any>ExternalModule).method() // ALWAYS avoid this
@leonardofreitass
leonardofreitass / user.ts
Created August 2, 2017 18:00
User model
User.fetchAll<User>()
.then((result) => {
});
@leonardofreitass
leonardofreitass / server.ts
Last active May 9, 2020 05:32
Express Server using TypeScript
class Server {
public app: express.Application;
public config: Config;
public static bootstrap(): Server {
return new Server();
}
constructor() {
this.app = express();
this.setup();
this.routes();