Skip to content

Instantly share code, notes, and snippets.

@Geal
Geal / future.c
Last active May 8, 2024 08:44
small future and promise library in C with pthreads
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <stdbool.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include "future.h"
@Geal
Geal / gist:31e7e11bba655d3c662e738043422d72
Last active September 22, 2022 13:36
bounded_producer.cpp
#include <condition_variable>
#include <mutex>
#include <thread>
#include <iostream>
#include <queue>
#include <chrono>
using namespace std;
class Queue {
@Geal
Geal / client.rs
Last active March 7, 2022 21:54
Rust and Unix domain sockets usage example * stream sockets (client.rs and server.rs) * datagram sockets (datagram_client.rs and datagram_server.rs) * example of writing to syslog (incomplete for now)
extern mod native;
use std::io::net::unix::UnixStream;
use std::path::posix::Path;
use std::str;
use std::rt::rtio::IoFactory;
use native::io;
fn main() {
[package]
name = "warp-tracing"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
futures-util = "0.3.18"
tokio = { version = "1.14.0", features = ["full"] }
use std::{
fs::File,
str::from_utf8,
io::{Read, Write},
os::unix::io::AsRawFd,
};
fn main() -> std::io::Result<()> {
let mut write_file = File::create("test.txt")?;
let mut read_file = File::open("test.txt")?;
@Geal
Geal / gist:1393956
Created November 25, 2011 16:50
Macro displaying __FUNCTION__ and __LINE__ and concatenating its arguments
#define STR(x) #x
#define STR1(x) STR(x)
#define DEBUGME(a) OutputDebugStringA( "[DEBUG| " __FUNCTION__ ":" STR1(__LINE__) "] " a "\n")
@Geal
Geal / install-sysdig.sh
Last active May 20, 2020 13:44
Curl install pattern
v=`curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig`; if [ "7777a6bb3188993fc70fd8124c03e2880f034be6 -" != "`echo -n "$v" | sha1sum`" ]; then echo "invalid hash"; else `echo "$v" | sudo bash`; fi
package epsi.com.phototest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.media.MediaScannerConnection;
import android.net.Uri;
@Geal
Geal / fork-exec.rs
Last active December 24, 2019 02:26
extern crate nix;
extern crate libc;
use nix::sys::signal::*;
use nix::unistd::*;
use nix::fcntl::{fcntl,FcntlArg,FdFlag,FD_CLOEXEC};
use libc::c_char;
use std::mem;
use std::str;
#![cfg(feature = "alloc")]
use jemallocator;
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
use nom::{
branch::alt,