Skip to content

Instantly share code, notes, and snippets.

View akoskovacs's full-sized avatar

Ákos Kovács akoskovacs

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / miner.rb
Created March 12, 2018 00:13
Example Ruby miner. The way Bitcoin miners try to find a hash for a given complexity and transaction
# Mining example
require 'benchmark'
require 'openssl'
def hash_ok?(hash, complexity)
hash.start_with?("0" * complexity)
end
# Appending a nonce the the
def create_target(str, nonce)
@akoskovacs
akoskovacs / redditer.js
Last active October 28, 2018 05:11
Plain Reddit reader for the console with Node.js
// esversion: 6;
/// SETTINGS ///
// Maximum number of posts to be showed
const MAX_COUNT = 10;
// List of the subreddits, the desired sort order (multiple is allowed)
// and count of posts
const SUBREDDITS = [
{
name: 'spacex',
@akoskovacs
akoskovacs / leaf.cxx
Last active January 28, 2019 21:24
Leaf function example
// Compile with: gcc -O2 leaf.c -o leaf
// Proof: https://godbolt.org/z/vg1FSS
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
// Not actually tweaking the stack (except for ret)
int leaf_me_alone(int a, int b)
{
return a*a + b*b / 2;
@akoskovacs
akoskovacs / rayson.json
Created March 7, 2020 02:35
rayson.json
[
["function", ["hello", [], [
["call", ["console", "log"], ["hello, world"]],
["return", []]
]
]
],
["function", ["addTwoNums", ["a", "b"], [
["return", [
["+", ["a", "b"]]