Skip to content

Instantly share code, notes, and snippets.

View akoskovacs's full-sized avatar

Ákos Kovács akoskovacs

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / scale.notes
Last active November 8, 2015 21:50
WAV file tone writer
440 500
495 500
550 500
586 500
660 500
733 500
825 500
880 500
@akoskovacs
akoskovacs / bf.cxx
Created November 23, 2015 01:29
Small Brainfuck interpreter in C++
#include <iostream>
#include <fstream>
#include <cstring>
namespace bfck {
#define BRAINFUCK_ARRAY_SIZE 30000
void interpretFile(const char *);
void eval(int = 0);
char bfa[BRAINFUCK_ARRAY_SIZE];
int bptr;
@akoskovacs
akoskovacs / progress.c
Last active December 6, 2015 22:09
Console progress bar example
#include <stdio.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
int i, j;
for (i = 0; i <= 100; i++) {
fprintf(stderr, "\rLoading [");
for (j = 0; j < 100; j++) {
fprintf(stderr, "%c", (i > j) ? '=' : '-');
@akoskovacs
akoskovacs / fizzbuzz.c
Last active April 26, 2018 11:35
FizzBuzz magic in C
/* Totally patented by Ákos Kovács */
#include <stdio.h>
void fizzbuzz(int n)
{
int i;
char fb[][5] = { "Fizz", "Buzz", "%d" };
for (i = 1; i <= n; i++) {
*((*fb)+4)=i%15?0x0:0x07;
printf(*(fb+(i%5?!!(i%3)*2:!!(i%3))), i);