Skip to content

Instantly share code, notes, and snippets.

View ruda's full-sized avatar
🐵
INFINITE PAGE FAULT. CPU HALTED.

Rudá Moura ruda

🐵
INFINITE PAGE FAULT. CPU HALTED.
View GitHub Profile
@ruda
ruda / blackflag.txt
Created May 22, 2015 03:08
⚑ BLACK FLAG ⚑
B L A C K
### ###
### ### ### ###
### ### ### ###
### ### ### ###
### ### ### ###
### ###
F L A G
@ruda
ruda / interpolation_search.py
Created May 26, 2015 01:09
Interpolation Search
# From http://data.linkedin.com/blog/2010/06/beating-binary-search
def interpolation_search(key, array, min, max):
"""
Interpolation search.
>>> a = [7, 28, 28, 41, 45, 50, 59, 68, 74, 96]
>>> k = 59
>>> print interpolation_search(k, a, 0, 99)
6
"""
@ruda
ruda / waste.txt
Created September 19, 2012 01:39
WASTE (ASCII Art)
______//
(__) \\
W.A.S.T.E.
@ruda
ruda / apple.txt
Created September 21, 2012 00:36
Apple (ASCII art)
../..
( (
\_._/
Apple
@ruda
ruda / buffer.el
Last active October 12, 2015 08:48
Kill all buffers.
(defun kill-all-buffers ()
"Kill all buffers."
(interactive)
(dolist (buffer (buffer-list))
(kill-buffer buffer)))
// pwmanager.js - RSTM
var crypto = require('crypto');
function encrypt(plaintext, keyword) {
var cipher = crypto.createCipher('aes-256-ctr', keyword);
var ciphertext = cipher.update(plaintext, 'utf8', 'hex');
ciphertext += cipher.final('hex');
return ciphertext;
};
@ruda
ruda / nsplit.py
Last active June 13, 2016 02:09
Split iterable in group of 'n' values and yield these values.
def nsplit(iterable, n):
result = []
for i, x in enumerate(iterable, 1):
result.append(x)
if i % n == 0:
yield result
result = []
if result:
yield result
@ruda
ruda / concorrência.md
Last active October 9, 2016 12:22
O que é concorrência em computação?

O que é concorrência em computação? Olhando a entrada de concurrency na Wikipedia em Inglês:

In computer science, concurrency is the decomposability property of a program, algorithm, or problem into order-independent or partially-ordered components or units. This means that even if the concurrent units of the program, algorithm, or problem are executed out-of-order or in partial order, the final outcome will remain the same.

Aqui duas idéias são importantes, (1) order-independent (ordem independente) e (2) partially-ordered components (parcialmente ordenados). Explicando, digamos que um sistema possua uma ação A e uma ação B. Se A não causa B e B não causa A, então temos uma ordem independente (1). Se A causa B então aqui temos uma ordem parcial (2).

Um programa que possui a propriedade (1) permite uma execução em qualquer ordem da ação (primeiro A, depois B; primeiro B, depois A) já a propriedade (2) permite que ordens distintas (A causa B e X causa Y) possam ser executadas (sequencialmente) co

@ruda
ruda / createpng.js
Last active October 9, 2017 02:32
Create PNG and allow download from browser [HTML canvas]
// Rudá Moura <ruda.moura@gmail.com>
window.onload = function() {
createPNG('png1', 'red');
createPNG('png2', 'blue');
createPNG('png3', 'green');
createPNG('png4', 'turquoise');
}
function createPNG(name, color) {
@ruda
ruda / ColorPicker.applescript
Created October 11, 2017 01:12
Show Color Picker and wait for user selection, then return the hex color number to the clipboard.
(*
* Show Color Picker and wait for user selection, then return the hex color number to the clipboard.
* For input, it can use a RGB color from the clipboard (valid formats: #RRGGBB or #RGB).
*
* Copyright © 2012-2017 Rudá Moura. All rights reserved.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting