Skip to content

Instantly share code, notes, and snippets.

View dptole's full-sized avatar

dptole

View GitHub Profile
@dptole
dptole / .vimrc
Last active March 4, 2023 15:16
My Vim configurations.
set sts=2
set ts=2
set sw=2
set et
set number
set encoding=utf-8
syntax on
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
autocmd BufReadPost,BufNewFile *.elm setfiletype haskell
@dptole
dptole / ieee754.cpp
Last active August 29, 2015 14:09
Takes a floating point number and show its binary representation.
#include <iostream>
#include <stdio.h>
using namespace std;
void printDouble(double d) {
unsigned long long i = *(unsigned long long *) &d;
for(int j = 63; j >= 0; j--) {
cout << ((i >> j) & 1);
@dptole
dptole / wp-trick.php
Last active November 12, 2019 12:04
WP-trick
// Evitar que o wordpress redirecione caso o host e porta
// utilizados para acessar o cms sejam diferente daqueles
// configurados na instalação
// Adicionar no fim do arquivo wp-load.php
remove_all_actions('template_redirect');
@dptole
dptole / failed-login-attempt.sh
Created August 22, 2017 15:57
List all the failed login attempts into your server
#!/bin/bash
# I'm using "Aug 22" as a date example, you MUST replace this information.
cat /var/log/secure |
grep '^Aug 22' |
grep 'Failed' |
sed -r 's/^.*? ([0-9]{1,3}(\.[0-9]{1,3}){3}).*/https:\/\/db-ip.com\/\1/' |
sort |
uniq
@dptole
dptole / Zumber.js
Last active November 28, 2019 14:17
Zumber, weird numbers.
-function() {
function Zumber(array) {
if(!(this instanceof Zumber))
return new Zumber(array);
if(!(
array instanceof Array &&
array.length > 10 &&
array.every(function(item, index) {
return typeof(item) === 'string' && item.length === 1 && !~array.indexOf(item, index + 1);
@dptole
dptole / letsencrypt-certbot-certonly.sh
Last active January 9, 2019 15:48
Generate your free certificate with Let's Encrypt! https://letsencrypt.org/
#!/bin/bash
# Created at 2018-10-15
# CHECKUPS
echo "LAST CHANCE TO BACK UP YOUR OLD CERTIFICATES!"
echo ""
read
echo "THE DESIGNATED DOMAIN MUST BE ACCESSIBLE FROM THE INTERNET FOR OWNERSHIP VERIFICATION!"
@dptole
dptole / docker-fix.sh
Last active August 24, 2020 09:47
Fix docker container when it can't connect to the internet https://stackoverflow.com/a/20431030
# Source
# https://stackoverflow.com/a/20431030
# Turn off docker service
sudo service docker stop
# Delete iptables
sudo iptables -t nat -F
# Bring docker ethernet interface down
@dptole
dptole / dynamic_decorator.py
Last active March 21, 2019 00:50
Dynamically add decorators into python functions
# -*- coding: utf-8 -*-
"""
$ python dynamic_decorator.py
func_to_be_dynamically_decorated(1, 2)
3
unreg = add_dynamic_decorator('func_to_be_dynamically_decorated', dynamic_decorator_1)
<function unreg at 0x7f5260d1f9b0>
func_to_be_dynamically_decorated(1, 2)
4
@dptole
dptole / numero-para-texto.php
Created October 10, 2019 23:57
Converter números para texto em PHP
<?php
// UDC = Unidade Dezena Centena
function numeroParaTextoUDC($numero) {
$_ucd = "$numero";
while(strlen($_ucd) < 3)
$_ucd = "0$_ucd";
switch(+$_ucd) {
case 0: return array("zero");
@dptole
dptole / Preferences.sublime-settings
Last active November 3, 2019 02:33
My sublime preferences
{
"animation_enabled": false,
"auto_close_tags": false,
"auto_complete": false,
"auto_complete_commit_on_tab": false,
"auto_complete_with_fields": false,
"auto_indent": false,
"auto_match_enabled": false,
"caret_style": "blink",