Skip to content

Instantly share code, notes, and snippets.

View akoskovacs's full-sized avatar

Ákos Kovács akoskovacs

View GitHub Profile
@akoskovacs
akoskovacs / chat.html
Created June 15, 2017 00:15
Sinatra SSE chatserver + JS client
<html>
<head><title>Chat</title></head>
<script>
window.onload = function() {
var chatRoom = new EventSource("/subscribe");
console.log(chatRoom);
chatRoom.onmessage = function(event) {
var cw = document.getElementById("chat-window");
cw.innerHTML += "<p>" + event.data + "</p><hr />";
console.log(event);
@akoskovacs
akoskovacs / bfcompiler.rb
Last active July 6, 2017 21:52
Brainfuck native compiler for i386, x86-64
#!/usr/bin/ruby
require 'tempfile'
CELL_SIZE = 30_000
ASM_STUB_X86_64 =<<EOF
.comm bf_cell, #{CELL_SIZE}
.global write_byte
.global sys_exit
.global _start
@akoskovacs
akoskovacs / weird_if.c
Created January 20, 2017 19:06
Implementing if statement in GNU C with goto
#include <stdio.h>
/*
* if (argc == 1) {
* printf("argc equals one\n");
* } else {
* printf("argc is not one (%d)\n", argc);
* }
* return argc;
*/
@akoskovacs
akoskovacs / eject.c
Created December 28, 2016 02:45
Eject CDROM ioctl() example
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <linux/cdrom.h>
@akoskovacs
akoskovacs / rdsh.c
Last active December 12, 2016 21:14
Really dumb shell
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
@akoskovacs
akoskovacs / time.html
Last active November 17, 2018 22:51
Display the current time
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>What's the time, please?</title>
<script type="text/javascript" charset="utf-8">
window.onload = function() {
var body_tag = document.getElementsByTagName("body")[0];
var timer_div = document.getElementById("timer");
function getRandomColor() {
@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);
@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 / 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 / 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