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 / ams1117.txt
Created December 15, 2018 18:37
AMS1117 (Voltage Regulator)
AMS1117 (SOT-223)
=========
.---------------.
| AMS1117 |
'--+----+----+--'
| | |
1 2 3
Adj Vout Vin
GND
@ruda
ruda / calcx86.y
Created October 2, 2018 22:40
Simple arithmetic expressions (+, -, * / ) to x86 code for macOS
%{
#include <stdio.h>
#include <ctype.h>
#include <math.h>
int yylex(void);
void yyerror(char *);
int level;
%}
@ruda
ruda / maze.c
Created September 24, 2018 00:03
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
int
main(int argc, char *argv[])
{
struct winsize ws;
@ruda
ruda / Garden.ps
Created June 22, 2018 20:46
Geometric figures resembling flowers
%!
/inch {72 mul} def
/cm {2.54 div 72 mul cvi} def
/maxint {2 32 exp 1 sub} def
/urand {rand maxint div} def
/forward {0 exch rlineto} def
/right {neg rotate} def
/left {rotate} def
/center {4 inch 5 inch moveto} def
/*
* From http://c-faq.com/misc/hexio.html
* modified for padding zeros - ruda
*/
#define NULL 0
char *
baseconv(unsigned int num, int base)
{
@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
@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 / 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 / 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
// 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;
};