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 / gc.c
Created January 19, 2020 13:58
// $ gcc -fPIC -shared -o libgc.so gc.c
// $ LD_PRELOAD=$(pwd)/libgc.so ghci
#include <stdlib.h>
void GarbageCollect() {
exit(1);
}
void hs_init() {

Spawning async tasks in GTK apps

I'm trying to spawn async tasks in a GTK app using GLib's [MainContext::spawn][1]. Questions:

  • I'm not sure how to get MainContext of a GTK [Application][2]. I think Application should already have a MainContext, and I'm not sure if creating a new one is safe.

  • In a task spawned by MainContext::spawn I'm not sure which async I/O function/traits I can use. I think I can use AsyncRead/AsyncWrite from futures but that's not documented.

  • In a task I'm not sure how to spawn more tasks. Should I pass a copy of MainContext to my tasks and use it to spawn more tasks via the spawn method?

# Sample TOML configuration file for building Rust.
#
# To configure rustbuild, copy this file to the directory from which you will be
# running the build, and name it config.toml.
#
# All options are commented out by default in this file, and they're commented
# out with their default values. The build system by default looks for
# `config.toml` in the current directory of a build for build configuration, but
# a custom configuration file can also be specified with `--config` to the build
# system.
[package]
name = "blocking_test"
version = "0.1.0"
authors = ["Ömer Sinan Ağacan <[email protected]>"]
edition = "2018"
[dependencies]
futures-preview = { version = "0.3.0-alpha.18", features = ["async-await", "nightly"] }
futures-util-preview = "0.3.0-alpha.18"
tokio = { git = "https://github.com/tokio-rs/tokio.git", features = ["timer"] }
@osa1
osa1 / Cargo.toml
Last active September 21, 2019 16:56
[package]
name = "delay_test"
version = "0.1.0"
authors = ["Ömer Sinan Ağacan <[email protected]>"]
edition = "2018"
[dependencies]
tokio = { git = "https://github.com/tokio-rs/tokio.git", features = ["timer"] }
futures-preview = { version = "0.3.0-alpha.18", features = ["async-await", "nightly"] }
futures-util-preview = "0.3.0-alpha.18"
@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 <[email protected]>.
extern crate cairo;
extern crate gdk;
extern crate gtk;
use gdk::{Atom, DragAction, DragContext, ModifierType, Screen};
use gtk::*;
[package]
name = "listbox-dnd"
version = "0.1.0"
authors = ["Ömer Sinan Ağacan <[email protected]>"]
edition = "2018"
[dependencies]
cairo-rs = { git = "https://github.com/gtk-rs/cairo.git" }
gdk = { git = "https://github.com/gtk-rs/gdk.git" }
lazy_static = "1.2.0"
#!/bin/bash
set -x
execs=( CAPS caps dmenu_open eng hstags keys trk )
mkdir $HOME/bin || true
for exec in "${execs[@]}"; do
ln -s `pwd`/$exec $HOME/bin/$exec
#!/bin/bash
set -e
set -x
git submodule update --init
make distclean
./boot
./configure
@osa1
osa1 / gist:626e0dda076378a55a8ef4b06d28108a
Last active September 4, 2018 07:36
Show commit hash in when viewing a commit in fugitive
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
index 1cc3d44..4a99b06 100644
--- a/autoload/fugitive.vim
+++ b/autoload/fugitive.vim
@@ -1524,7 +1524,7 @@ function! fugitive#BufReadCmd(...) abort
if b:fugitive_display_format
call s:ReplaceCmd([dir, 'cat-file', b:fugitive_type, rev])
else
- call s:ReplaceCmd([dir, 'show', '--no-color', '--pretty=format:tree%x20%T%nparent%x20%P%nauthor%x20%an%x20<%ae>%x20%ad%ncommitter%x20%cn%x20<%ce>%x20%cd%nencoding%x20%e%n%n%s%n%n%b', rev])
+ call s:ReplaceCmd([dir, 'show', '--no-color', '--pretty=format:commit%x20%H%ntree%x20%T%nparent%x20%P%nauthor%x20%an%x20<%ae>%x20%ad%ncommitter%x20%cn%x20<%ce>%x20%cd%nencoding%x20%e%n%n%s%n%n%b', rev])