Skip to content

Instantly share code, notes, and snippets.

View osa1's full-sized avatar

Ömer Sinan Ağacan osa1

View GitHub Profile
@osa1
osa1 / main.dart
Last active March 20, 2024 08:05
void main() {
final List<int> list = [1, 2, 3];
final List<num> otherList = list; // unsound, but Dart allows
otherList.add(4.5); // unsoundness above requires runtime check here
}
@osa1
osa1 / demo.c
Last active February 4, 2024 06:27
ncurses alt, ctrl etc. key events
// It turns out people don't really know how to handle Alt+ch, or F[1, 12] keys
// etc. in ncurses apps. Even StackOverflow is full of wrong answers and ideas.
// The key idea is to skip ncurses' key handling and read stuff from the stdin
// buffer manually. Here's a demo. Run this and start typing. ESC to exit.
//
// To compile:
//
// $ gcc demo.c -o demo -lncurses -std=gnu11
#include <ncurses.h>
@osa1
osa1 / main.rs
Last active January 4, 2024 11:21
listbox-dnd
// A drag-and-drop example. You can drag the list items using the icon on the left, and drop them
// to other icons to move the list item. Originally listbox-dnd.c in GTK+ repository. Ported to
// gtk-rs by Ömer Sinan Ağacan <omeragacan@gmail.com>.
extern crate cairo;
extern crate gdk;
extern crate gtk;
use gdk::{Atom, DragAction, DragContext, ModifierType, Screen};
use gtk::*;
@osa1
osa1 / linkify.py
Created December 31, 2023 10:48
Convert markdown issue, PR, commit references to GitHub links (written by ChatGPT)
# linkify.py input.md output.md github-username github-repo-name
#
# Converts PR, issue, and commit references to full links.
#
# Written by ChatGPT.
import re
import requests
import argparse
@osa1
osa1 / randomwalk.lua
Created December 7, 2012 18:46
random walker
width = 640
height = 360
function newWalker()
return { x=width/2, y=height/2 }
end
function love.load()
love.graphics.setMode(width, height, false, false, 0)
walker = newWalker()
@osa1
osa1 / main.dart
Last active November 23, 2023 12:29
Strange Dart 11
/*
Bad type inference causes breakage when making a type more precise in covariant
position.
*/
class A {
const A();
}
const constA = const A();
@osa1
osa1 / gist:2757232
Created May 20, 2012 07:46
Lisp-style lazy-lists in Lua
function makeThunk(f, args)
return { tag = "thunk", f = f, args = args }
end
function evalThunk(t)
return t.f(unpack(t.args))
end
function cons(first, rest)
return { first = first,
@osa1
osa1 / egui_test.rs
Last active September 16, 2023 08:36
use eframe::egui;
fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
drag_and_drop_support: true,
initial_window_size: Some(egui::vec2(320.0, 240.0)),
..Default::default()
};
eframe::run_native(
"Native file dialogs and drag-and-drop files",
@osa1
osa1 / main.dart
Created July 19, 2023 12:10
Strange Dart 10
import 'dart:typed_data';
void main() {
final Int32List list = Int32List.fromList([1, 2, 3, 4, 5, 6]);
// Create a view, list without the first and last elements.
final Int32List view = Int32List.sublistView(list, 1, 5);
print(view); // [2, 3, 4, 5, 6]
// Do the same, this time using the `ByteBuffer` object.
@osa1
osa1 / hm.rs
Created June 15, 2023 16:23
HM type inference in Rust
/*
HM type inference with:
- Union-find for unification.
- Type variable levels for generalization.
Implementation became tricky because of the mutable level and link fields.
In this implementations links cannot form cycles (occurs check catches it), so we could use
`Rc<RefCell<..>>`-wrapped types. However: