Skip to content

Instantly share code, notes, and snippets.

View akoskovacs's full-sized avatar

Ákos Kovács akoskovacs

View GitHub Profile
@akoskovacs
akoskovacs / .vimrc
Created June 18, 2011 16:39
My .vimrc
syntax on
set autoindent
set smartindent
set nocp
filetype plugin on
au BufRead,BufNewFile *.rc set filetype=rc
set tabstop=4
set shiftwidth=4
set expandtab
set number
@akoskovacs
akoskovacs / chat.rb
Last active September 13, 2023 22:38
Ruby chat server
#!/usr/bin/env ruby
# Run with
# $ chmod +x chat.rb && ./chat.rb
# or
# $ ruby chat.rb
require 'socket'
require 'thread'
@akoskovacs
akoskovacs / pgen.rb
Created November 28, 2012 23:15
pgm picture generator (gray gradient pattern)
#!/usr/bin/env ruby
HEIGHT = 1024
WIDTH = 1024
f = File.new("sample.pgm", "w")
f.puts "P2"
f.puts "#{HEIGHT} #{WIDTH}"
f.puts 255
f.puts "# Generated by pgen.rb (C) Akos Kovacs"
HEIGHT.times do |row|
@akoskovacs
akoskovacs / hello.c
Created December 3, 2012 00:31
AkLisp hello, world module
#include <aklisp.h>
#include <stdio.h>
AKL_CFUN_DEFINE(hello, in, args)
{
printf("Hello, world from 'hello' module!\n");
/* Every function must return something,
the type of 'akl_value' */
return &NIL_VALUE;
}
@akoskovacs
akoskovacs / smod.c
Created January 5, 2013 14:42
Self modifing code in C.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*func_t)(void);
int main(int argc, char *argv[])
{
char *fstart = "\x55\x48\x89\xe5\x48\x31\xc0";
@akoskovacs
akoskovacs / scode.c
Created January 5, 2013 15:14
32bit self-modifying multiplying Intel code.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
typedef int (*func_t)(void);
int main(int argc, char *argv[])
{
/* push %ebp
@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
@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 / 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 / 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)))