Skip to content

Instantly share code, notes, and snippets.

View onlined's full-sized avatar

Ekin Dursun onlined

View GitHub Profile
@onlined
onlined / fire_and_forget.py
Created March 10, 2023 02:01
Easier and secure "fire and forget" for async tasks
import asyncio
def _create_fire_and_forget():
tasks = set()
def fire_and_forget(*args, **kwargs):
task = asyncio.create_task(*args, **kwargs)
tasks.add(task)
task.add_done_callback(tasks.discard)
@onlined
onlined / remove_none.py
Last active September 12, 2019 08:53
Removes unnecessary None return annotation from __init__ methods
from __future__ import annotations
from typing import List
import ast
import sys
def is_annotated_with_none_return(func: ast.FunctionDef) -> bool:
return (isinstance(func.returns, ast.NameConstant) and
@onlined
onlined / circular_buffer.hpp
Created November 3, 2018 01:47
A simple circular buffer implementation
#include <exception>
#include <algorithm>
#include <utility>
#include <cstdlib>
template <typename T>
class CircularBuffer {
private:
const size_t capacity;
size_t size;
@onlined
onlined / semaphore.c
Created September 4, 2018 07:28
A semaphore implementation with C11 threading libraries
#include <threads.h>
typedef struct {
int value;
mtx_t mutex;
cnd_t cv;
} sem_t;
int sem_init(sem_t *sem, int value) {
int result;
@onlined
onlined / qtest.sh
Last active October 23, 2017 20:33
Tester for FIFO logic of CENG334 HW2 (2016-2017 Spring)
#!/bin/bash
if [ -t 0 ]; then
echo "Please redirect input file to this script."
exit
fi
i=0
sorted_output=$(./simulator | tr -d ',' | sort -k11,11 -g)
@onlined
onlined / githubtablength.user.js
Last active March 29, 2017 10:10
Userscript setting GitHub tab length to 4
// ==UserScript==
// @name GitHub Tab Length
// @namespace https://gist.github.com/onlined
// @version 1.2.1
// @description Userscript setting GitHub tab length to 4
// @author Ekin Dursun
// @match https://*.github.com/*
// @grant none
// ==/UserScript==
@onlined
onlined / tester.sh
Created December 22, 2016 14:33
Tester for CENG315 Take Home 1
#!/bin/bash
# Put Makefile, inputs and this script in the same directory.
files2=({x..z}{1,2})
files3=({a..f}{1,2})
make &>/dev/null
ok=true
@onlined
onlined / sorts.c
Last active November 10, 2016 13:13
Comparison of different sort algorithms
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#define SWAP(x,y) do { int tmp = (x); (x) = (y); (y) = tmp; } while(false)
// For heapsort
#define LEFT(x) (2*(x)+1)