Skip to content

Instantly share code, notes, and snippets.

View akoskovacs's full-sized avatar

Ákos Kovács akoskovacs

View GitHub Profile
@akoskovacs
akoskovacs / morse.c
Created November 8, 2015 01:47
Convert English text to morse (small data size)
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MKEY(size, keys) ((keys)|((size)<<5))
#define MSIZE(m) ((m)>>5)
#define MSEQ(m) ((m)&0x1f)
@akoskovacs
akoskovacs / csv.rb
Last active November 3, 2015 19:45
Ruby on Rails style database interface for CSV files
class HeaderType
attr_reader :header
ATTRS = {string: :string, int: :int, number: :int, integer: :int }
def initialize
@header = []
end
# Define methods string, integer, etc.,
# for schema definition dynamically
class_eval do
ATTRS.each do |attr, type|
@akoskovacs
akoskovacs / tetris.ino
Last active August 29, 2015 14:05
Tetris theme for Arduino with the 16bit timer
#include <avr/io.h>
void changeFrequency(unsigned int freq)
{
int ocr = F_CPU/freq-1;
cli();
TCCR1A = _BV(COM1A0);
OCR1A = ocr;
sei();
}
@akoskovacs
akoskovacs / fb-flag.c
Created July 1, 2014 15:00
Raspberry Pi direct (memory-mapped) framebuffer drawing PoC.
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#define RGB565(r, g, b) (uint16_t)(b|(g<<5)|(r<<11))
@akoskovacs
akoskovacs / makepath.bat
Created September 16, 2013 12:26
Set path for Java @ElTe.
set PATH=%PATH%;"C:\Program Files\Java\jdk1.7.0_25\bin"
@akoskovacs
akoskovacs / attacher.rb
Created August 15, 2013 19:44
Attach to the first GNU screen
#!/usr/bin/env ruby
screens = `screen -ls`
screens.lines do |l|
if l =~ /\s+(\d+)\./
puts "Attaching to screen #{$1}..."
`screen -x #{$1}`
exit 1
end
end
@akoskovacs
akoskovacs / Pi.hs
Created June 2, 2013 19:35
Viéte Pi approximation algorithm in Haskell
make_pi :: Int -> Double
make_pi n = product [2.0/(a x)|x <- [0..n]] where
a 0 = 1.0
a 1 = sqrt 2
a n = sqrt(2+(a (n-1)))
@akoskovacs
akoskovacs / rb_lisp.rb
Created March 4, 2013 06:38
A very simple and awesome Lisp interpreter in ruby
# A very simple and awesome Lisp interpreter in ruby
# Usage:
# require './rb_lisp.rb'
# RBLisp::Interpreter.new("(print (+ 5 (* 99 5)))") # => will print 500
module RBLisp
class Value
attr_accessor :type, :value
def initialize(args)
@akoskovacs
akoskovacs / MyList.hs
Last active September 3, 2023 09:46
A simple Haskell linked list implementation
module MyList where
data MyList a = Cons a (MyList a)
| MyNil deriving (Show, Eq)
{-
A simple linked list module
Some examples:
mylist = (Cons 10 (Cons 99 (Cons 11 (Cons 1 MyNil))))
myHead myList # => 10
myTail myList # => Cons 99 (Cons 11 (Cons 1 MyNil))
@akoskovacs
akoskovacs / Main.hs
Last active December 14, 2015 08:29
N00b Haskell Matrix library (unready)
module Main where
import System.Environment (getArgs)
import Data.List
import Matrix
import IO
main :: IO ()
main = do
hSetBuffering stdout NoBuffering