Skip to content

Instantly share code, notes, and snippets.

View magnomp's full-sized avatar

Magno Machado magnomp

  • Cachoeiro de Itapemirim - ES
  • X @magnomp
View GitHub Profile
@magnomp
magnomp / Common.Bindings.pas
Created November 24, 2011 19:55
Helper class for defining live bindings for a TStringGrid
{ Created it because I found that defining the columns at design time isn't much productive.
Usage:
Consider CustomersBindingScope is a TBindScope and CustomersGrid is a TStringGrid, and
CustomerBindingScope.DataObject points to a TList<TCustomer> and TCustomer is declared as
follow:
type
TCustomer = class
public
property Name: String read FName write FName;
property Age: Integer read FAge write FAge;
@magnomp
magnomp / CodeAlign.pas
Created November 29, 2011 12:37
Code Alignment
if N < NMax then
begin
// Passo 2.2.1.1
z := BischoffAndDowsland(L1, W1, LBox, WBox, N + 1, NMax, X, Y, OffsetX + 0, OffsetY + W4, TmpBlocos, TmpBlockCount2, Cache) +
BischoffAndDowsland(L2, W2, LBox, WBox, N + 1, NMax, X, Y, OffsetX + L1, OffsetY + W5, TmpBlocos, TmpBlockCount2, Cache) +
BischoffAndDowsland(L3, W3, LBox, WBox, N + 1, NMax, X, Y, OffsetX + L1, OffsetY + W4, TmpBlocos, TmpBlockCount2, Cache) +
BischoffAndDowsland(L4, W4, LBox, WBox, N + 1, NMax, X, Y, OffsetX + 0, OffsetY + 0, TmpBlocos, TmpBlockCount2, Cache) +
BischoffAndDowsland(L5, W5, LBox, WBox, N + 1, NMax, X, Y, OffsetX + L4, OffsetY + 0, TmpBlocos, TmpBlockCount2, Cache);
end
else
@magnomp
magnomp / gist:1825662
Created February 14, 2012 10:38
Multi-tarefa em Arduino
/* Um led conectado ao pino 13 é acionado mediante um botão ligado ao pino 2. Paralelamente a
isso, um led conectado ao pino 3 pisca em intervalos de 1s */
#define BOTAO 2
#define LED_BOTAO 13
#define LED_PISCA 3
unsigned long start = 0;
int estado_led = LOW;
@magnomp
magnomp / Som.ino
Created July 8, 2013 22:54
Sketch para Arduino para geração de 8 sinais de audio em 8 pinos, cada um seguindo um padrão especifico de pulsos (um pulso no canal 1, dois pulsos no canal 2, etc). As bibliotecas de audio para Arduino têm a limitação de permitir gerar apenas um tom em um dado instante, ou quando muito tantos tons quanto forem os timers de hardware disponíveis …
#include <TimerOne.h>
#define FREQUENCIA 110 // hz
#define TEMPO_TOCANDO 200 // ms
#define TEMPO_PAUSA_CURTA 200 // ms
#define TEMPO_PAUSA_LONGA 1000 // ms
#define TOCANDO 0
#define PAUSA_CURTA 1
#define PAUSA_LONGA 2
@magnomp
magnomp / Foo.groovy
Created October 1, 2015 11:15
Mantendo dados em formulário após submissão com erro em Grails
class Foo {
String bar
}
@magnomp
magnomp / factorial.clj
Created August 18, 2023 01:25
Clojure Factorial
(ns hello)
(defn factorial
"Calcula o fatorial do numero dado"
[n]
(loop [i n acc 1]
(if (= i 1)
acc
(recur (- i 1) (* acc i)))))
@magnomp
magnomp / hello.clj
Created August 19, 2023 02:01
Prime factorization in Clojure
(ns hello)
(defn is-divisible-by
[number divisor]
(= (rem number divisor) 0))
(defn factor-by
[number factor acc]
(loop [n number acc1 acc]
(if (is-divisible-by n factor)