Skip to content

Instantly share code, notes, and snippets.

View paulera's full-sized avatar

Paulo Amaral paulera

View GitHub Profile
@paulera
paulera / MVC_notes.md
Last active October 19, 2017 08:18
Notes and ideas about MVC components

Just putting together notes about MVC implementation practices, for further use.

RequestContext

  • Singleton object, has all the information about the current request.
  • Can parse data (e.g. getPayloadAsJSON, getPayloadAsXML, readParamAsJSON, isMobile, etc).
  • Optimized singleton-ish getters. Data is parsed for the first time only when it is needed, and not re-processed if called again.

Router

  • Reponsible for understanding the requested URL and give direction of who (Controller and method) should handle it.
  • Uses the RequestContext to understand the request
@paulera
paulera / createUserExample.java
Last active November 3, 2017 16:37
Logic example of usage of IF, FOR and WHILE in a common and almost real situation
// User can try to create an account 3 times
// attempt = 1
// attempt = 2
// attempt = 3
// attempt = 4
// attempt = 5
// askForUsername, doesUserExist, createUser and showMessage are "fictional" functions
for (int attempt = 1; attempt <= 5; attempt = attempt + 1) {
@paulera
paulera / exploding-cards.md
Last active September 13, 2024 04:06
Exploding cards: Explodding Kittens variant, with regular playing cards

Exploding cards

This is a variant of the Exploding Kittens game rules, using regular playing cards

  • 1 deck: 3 to 8 players
  • 2 decks: up to 16 players

Objective

The last survivor wins the game. If you draw a Bomb card and don't have a Disarm card, you die.

Preparing the game

@paulera
paulera / git-drive.sh
Last active November 16, 2020 11:33
Watch for changes in a folder and commit with changes as message. Kinda like Google Drive using Git.
#!/bin/bash
#
# HAVE TO REVIEW THIS SCRIPT
#
FOLDER="/folder/to/watch/for/changes"
SLEEP_INTERVAL=3
@paulera
paulera / tictactoe.py
Created December 14, 2017 18:28
I am studying python and made this tictactoe game as first milestone. Not object oriented just because the course did not get there yet and wasn't the scope for this exercise.
from __future__ import print_function
import os
import random
import time
import sys
def clear():
"""
Clear the console
"""
@paulera
paulera / blackjack.py
Last active January 15, 2018 22:39
Blackjack game, exercise for a udemy course, unfinished
from __future__ import print_function
from random import shuffle
import os
import time
class Player(object):
def __init__(self):
self.hands = [ Hand() ]
self.funds = 0.0
def __repr__(self):
@paulera
paulera / decorators_study.py
Created January 21, 2018 21:14
Studying decorators and figuring out how to pass parameters. In this example, a decorator tag_decorate('h1') will wrap the result of a function in <h1>...</h1>
"""
Decorators with parameters study
In a simple decorator usage, the decorator function takes a callable object as
parameter (the function to be decorated, let's call it "target"), and returns
another callable which will be executed instead (let's call it "wrapper").
For this reason, it is essential that the wrapper accept the same parameters
as the target, and return an object of the same type.
The wrapper will have the target in scope, therefore can run it and return a
@paulera
paulera / server_config_notes.md
Created February 22, 2018 07:16
Server configuration

iptables

Security settings

iptables -F
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
#this is to get rid of null packets
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
#defend syn-flood attacks
@paulera
paulera / xdebug.php.ini
Last active January 25, 2019 09:30
PHP configuration for enabling XDebug, including profiler and tracer
; All settings: https://xdebug.org/docs/all_settings
; DEBUGGER
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_log=/tmp/xdebug/xdebug.log
xdebug.var_display_max_data=2048
xdebug.var_display_max_depth=5
@paulera
paulera / file_permissions.sh
Created February 26, 2018 15:07
Set file permissions 775 for dirs and 664 for files
#!/bin/bash
#
# This will set
# Directories: 775 (read-write-exec for owner and group, read-exec for others)
# Files: 664 (read-write for owner and group, read for others)
# for all files expect .git folder.
# --> Remove `-name .git -prune -o` to extend it to git files.
find . -name .git -prune -o -type d -exec chmod 775 {} \;
find . -name .git -prune -o -type f -exec chmod 664 {} \;