Skip to content

Instantly share code, notes, and snippets.

Avatar

Mahmoud Al-Qudsi mqudsi

View GitHub Profile
@mqudsi
mqudsi / bisect_vim.sh
Created Dec 17, 2021
A script to bisect vim portably
View bisect_vim.sh
#!/bin/sh
# set -x
# vim is really hard to run portably; I can't seem to get `set rtp=./runtime/`
# to actually work, so we build it with a prefix pointing to $PWD and then
# symlink `share/vim/` so it points to the files we need.
if mkdir share 2>&1 >/dev/null; then
ln -s $(pwd) share/vim
fi
@mqudsi
mqudsi / github_release_updater.fish
Created Oct 20, 2021
Update a folder/file from the latest matching GitHub release
View github_release_updater.fish
#!/usr/bin/env fish
# Declare some constants to be used later
set -g filename omnisharp-win-x64.zip
set -g base_url https://github.com/OmniSharp/omnisharp-roslyn
set -g release_file current_release.txt
if ! type -q wsl.exe
# Running on actual Linux
set filename omnisharp-linux-x64.tar.gz
end
@mqudsi
mqudsi / UWP Modal Dialog.cs
Created Aug 20, 2021
Create a blocking/modal dialog with a new window on UWP. No dependencies.
View UWP Modal Dialog.cs
private async void Settings_Click(object sender, PointerRoutedEventArgs e)
{
var mainViewId = ApplicationView.GetForCurrentView().Id;
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
var popupClosed = new TaskCompletionSource<bool>();
Window settingsWindow = null;
var mainWindow = Window.Current;
@mqudsi
mqudsi / WebView2Extensions.cs
Last active Jan 13, 2021
WebView2 Extension Methods
View WebView2Extensions.cs
// Copyright (c) Mahmoud Al-Qudsi, NeoSmart Technoogies. All rights reserved.
// Licensed under the MIT License.
namespace NeoSmart.WebExtensions
{
static class WebView2Extensions
{
private static readonly ILogger Logger = Serilog.Log.Logger;
public static void Navigate(this WebView2 webview, Uri url)
{
@mqudsi
mqudsi / JsonRequest.cs
Created Apr 29, 2020
Asynchronous Utf8JsonReader parser
View JsonRequest.cs
using System;
using Serilog;
using System.IO;
using System.Threading.Tasks;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Buffers;
using System.Net;
namespace MessageClient
@mqudsi
mqudsi / StreamSequence.cs
Created Apr 29, 2020
StreamSequence, a stream-to-ReadOnlySequenceSegment<byte> wrapper
View StreamSequence.cs
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Buffers;
namespace MessageClient
{
class StreamSequence : IDisposable
{
@mqudsi
mqudsi / ffi-fn-registration.rs
Created Dec 23, 2018
A rust snippet to convert an anonymous function (or closure?) into an FFI-compatible callback
View ffi-fn-registration.rs
use std::os::raw::c_void;
extern {
fn register_callback(callback: extern fn(*const c_void, u32), user: *const c_void);
}
fn register<F: Fn(u32)>(f: F) {
extern fn handler<F: Fn(u32)>(f_ptr: *const c_void, val: u32) {
let f = unsafe { &*(f_ptr as *const F) };
f(val)
}
@mqudsi
mqudsi / spawntest.c
Last active Mar 5, 2018
Test for correct posix_spawn behavior when pgrp = 0
View spawntest.c
#include <errno.h>
#include <signal.h>
#include <spawn.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define nullptr 0
View magic.js
$(document).ready(function () {
$("select.magic").each(function () {
var select = $(this);
if (!select.hasOwnProperty("removedExtraneous")) {
select.removedExtraneous = [];
}
var filterFunction = function () {
var oldVal = select.val();
select.children("option.extraneous").each(function () {
@mqudsi
mqudsi / gist:4197573
Created Dec 3, 2012
GCC replacement of hard-coded null %s parameter
View gist:4197573
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main:
Leh_func_begin1:
pushq %rbp
Ltmp0:
movq %rsp, %rbp
Ltmp1:
subq $16, %rsp