Skip to content

Instantly share code, notes, and snippets.

View hugollm's full-sized avatar

Hugo Mota hugollm

  • Montes Claros - MG - Brasil
View GitHub Profile
@hugollm
hugollm / gist:4733267
Last active December 12, 2015 06:59
php wtf ~ php's (regular) sorting algorithm is totally unpredictable with mixed types
<?php
$array1 = array("a","b","4",5,4,"true","TRUE",true, false, "c", "d");
$array2 = array("a","b","4",5,4,"true","TRUE",true, false, "c");
sort($array1);
sort($array2);
dump($array1);
dump($array2);
@hugollm
hugollm / remove_diacritics.php
Created May 10, 2013 01:43
Brainstorming functions to convert diacritics into ASCII
/*
Convert common diacritics in portuguese language.
*/
function convertPortugueseDiacritics($string)
{
$from = 'áéíóúãõàèìòùçñüïÁÉÍÓÚÃÕÀÈÌÒÙÇÑÜÏ';
$to = 'aeiouaoaeioucnuiAEIOUAOAEIOUCNUI';
$from = preg_split('//u', $from, -1, PREG_SPLIT_NO_EMPTY);
$to = str_split($to);
@hugollm
hugollm / pdo_test.php
Last active December 19, 2015 08:09
Exemplo de conexão/consulta a banco MySql usando PDO.
<?php
// parametros de conexão
$host = 'localhost';
$dbname = 'arsenal';
$username = 'root';
$password = '';
// opcional, porém importante
$options = array(
@hugollm
hugollm / sublime-settings.json
Last active February 8, 2019 12:30
My Sublime Text 3 settings
{
"auto_complete_commit_on_tab": true,
"color_scheme": "Packages/Color Scheme - Default/Mariana.sublime-color-scheme",
"default_line_ending": "unix",
"draw_white_space": "selection",
"ensure_newline_at_eof_on_save": true,
"font_size": 10,
"ignored_packages":
[
"Vintage"
@hugollm
hugollm / sublime-keymap.json
Last active February 5, 2019 13:38
My Sublime Text 3 key bindings
[
{ "keys": ["ctrl+q"], "command": "toggle_comment" },
{ "keys": ["ctrl+o"], "command": "move_to", "args": {"to": "eol", "extend": false} },
{ "keys": ["ctrl+u"], "command": "move_to", "args": {"to": "bol", "extend": false} },
{ "keys": ["ctrl+k", "ctrl+k"], "command": "toggle_bookmark" },
]
# disable status bar
set -g status off
# set scrollback history to 10000 (10k)
set -g history-limit 10000
# fixes esc delay
set -sg escape-time 1
{
"line_numbers": false,
"gutter": false,
"draw_centered": true,
"wrap_width": 230,
"scroll_past_end": true
}
@hugollm
hugollm / simple-postgresql-setup.md
Last active November 3, 2016 20:04
Simple Postrgresql setup

Install Postgresql server:

sudo apt install postgresql-9.5

Edit postgresql.conf to make Postgresql listen to all network interfaces (allow external connections):

listen_addresses = '*'

If you want just IPV4 connections:

@hugollm
hugollm / spotify-pause.txt
Created March 11, 2017 01:25
Adding shortcut to play/pause music on Spotify (if media key is not already working)
Whisker menu > Keyboard > Application Shortcuts > Add
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
@hugollm
hugollm / bug.py
Created April 9, 2017 17:17
A bug that I found with python http.cookies.SimpleCookie
# watch -n 1 python3 -m unittest bug.py
from unittest import TestCase
from http.cookies import SimpleCookie
class BugTestCase(TestCase):
def test_bug(self):
morsel = list(SimpleCookie('token=abc; HttpOnly; SameSite=Strict').values())[0]