Skip to content

Instantly share code, notes, and snippets.

@gkbrk
gkbrk / main.rs
Created January 8, 2016 21:28
Simple idle clicker game in Rust
#[macro_use] extern crate conrod;
extern crate find_folder;
extern crate piston_window;
use conrod::{Labelable, Positionable, Sizeable, Colorable, Theme, Ui, Widget};
use conrod::color;
use piston_window::{EventLoop, Glyphs, PistonWindow, UpdateEvent, WindowSettings};
struct GameState {
coins: u64,
@gkbrk
gkbrk / Cargo.toml
Last active March 4, 2019 05:37
Asynchronous server example in Rust
[package]
name = "rust-async-qotd"
version = "0.1.0"
authors = ["Gökberk Yaltıraklı <webdosusb@gmail.com>"]
[dependencies]
tokio = { git = "https://github.com/tokio-rs/tokio" }
rand = "0.3"
@gkbrk
gkbrk / encode-json.py
Created December 3, 2019 03:08
JSON Encoder - unbird example
def check_encode(value):
import json
return json.loads(encode(value)) == value
def encode(value):
if isinstance(value, bool):
if value:
return "true"
else:
@gkbrk
gkbrk / client.py
Created August 10, 2015 16:06
Python client test
import curses
import sys
import random
import hackchat
import threading
class HackClient:
def __init__(self, nick, channel):
self.nick = nick
self.channel = channel
@gkbrk
gkbrk / titan-conquest-bot.py
Created August 1, 2019 00:17
Game bot for Titan Conquest
#!/usr/bin/env python3
import requests
import re
from bs4 import BeautifulSoup
UA = "Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0"
USERNAME = "usernameHere"
PASSWORD = "passwordHere"
ROOT = "https://titanconquest.com/"
WORKER = f"{ROOT}worker.php"
@gkbrk
gkbrk / whois.rs
Created December 5, 2015 17:43
Rust whois client
use std::io::prelude::*;
use std::net::TcpStream;
use std::io::BufReader;
use std::env;
fn get_tld_server(tld: &str) -> Option<String> {
let mut stream = TcpStream::connect("whois.iana.org:43").unwrap();
stream.write_all(format!("{}\n", tld).as_bytes()).unwrap(); //Send the tld
let reader = BufReader::new(stream);
@gkbrk
gkbrk / server.c
Created June 25, 2021 22:31
Chat server using the poll() API
#include <arpa/inet.h>
#include <poll.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
@gkbrk
gkbrk / slowloris.py
Last active January 13, 2022 09:28
Slowloris implementation in Python. https://github.com/gkbrk/slowloris
import socket
import random
import time
import sys
log_level = 2
def log(text, level=1):
if log_level >= level:
print(text)
@gkbrk
gkbrk / main.c
Last active January 15, 2022 00:02
Thanos-snap half of your files out of existence
#define _XOPEN_SOURCE 500
#include <assert.h>
#include <dirent.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
@gkbrk
gkbrk / rust_md5.md
Created December 10, 2015 20:57
Rust MD5 [AdventOfCode]

Is Rust's MD5 Slow? Heck no!

Today I came across this post on the Rust subreddit. Basically it is comparing two MD5 Miners written in Python and Rust. The miner is written for a code challenge called Advent of Code.

To be honest, speed is one of the things I love about Rust, so seeing Rust being blown away by Python (which I also like and use a lot) made me sad. I decided to make this a bit more fair for Rust so I made a very short piece of Rust code to complete this challenge FAST.

The challenge

The challenge, as written on the Advent of Code page is as follows:

  • You are given a key, for example abcdef.
  • You are looking for a string that is made by taking the MD5 of this key plus a number. This hash has to start with 5 leading zeros. (Like abcdef609043)