Skip to content

Instantly share code, notes, and snippets.

View mqudsi's full-sized avatar

Mahmoud Al-Qudsi mqudsi

View GitHub Profile
@mqudsi
mqudsi / NameCase.cs
Created April 25, 2012 02:51
Function for correcting capitalization of user-entered names
namespace NeoSmart
{
public static class Utils
{
//This function will only attempt to capitalize the first letter, etc. of a name
//if and only if the user appears to have entered all caps or all lowercase
public static string ProperCase(string stringToFormat)
{
System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Globalization.TextInfo textInfo = cultureInfo.TextInfo;
@mqudsi
mqudsi / gist:4154289
Created November 27, 2012 13:46
Redis Crashes

Premise: a small rant about software reliability.

I'm very serious about software reliability, and this is not just a good thing. It is good in a sense, as I tend to work to ensure that the software I release is solid. At the same time I think I take this issue a bit too personally: I get upset if I receive a crash report that I can't investigate further for some reason, or that looks like almost impossible to me, or with an unhelpful stack trace.

Guess what? This is a bad attitude because to deliver bugs free software is simply impossible. We are used to think in terms of labels: "stable", "production ready", "beta quality". I think that these labels are actually pretty misleading if not put in the right perspective.

Software reliability is an incredibly complex mix of ingredients.

@mqudsi
mqudsi / gist:4197573
Created December 3, 2012 19:59
GCC replacement of hard-coded null %s parameter
.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
@mqudsi
mqudsi / magic.js
Last active November 6, 2015 23:48
$(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 / spawntest.c
Last active March 5, 2018 01:33
Test for correct posix_spawn behavior when pgrp = 0
#include <errno.h>
#include <signal.h>
#include <spawn.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define nullptr 0
@mqudsi
mqudsi / ffi-fn-registration.rs
Created December 23, 2018 00:30
A rust snippet to convert an anonymous function (or closure?) into an FFI-compatible callback
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 / menu.lst
Created November 22, 2011 17:17
Sample EasyBCD NeoGrub configuration file used to dual-boot XP/Vista, hiding the Vista drive when booting into XP.
# NeoSmart NeoGrub Bootloader Configuration File
#
# This is the NeoGrub menu.lst file, and should be located at x:\NST\menu.lst
# (where x = your "system" partition i.e. the one containing all of the boot files)
# Please see the EasyBCD Documentation for information on how to create/modify entries
# http://neosmart.net/wiki/display/EBCD
default 0
timeout 10
@mqudsi
mqudsi / JsonRequest.cs
Created April 29, 2020 19:23
Asynchronous Utf8JsonReader parser
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 / WebView2Extensions.cs
Last active January 13, 2021 05:44
WebView2 Extension Methods
// 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 / UWP Modal Dialog.cs
Created August 20, 2021 16:14
Create a blocking/modal dialog with a new window on UWP. No dependencies.
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;