Skip to content

Instantly share code, notes, and snippets.

View mqudsi's full-sized avatar

Mahmoud Al-Qudsi mqudsi

View GitHub Profile
mqudsi / NameCase.cs
Created April 25, 2012 02:51
Function for correcting capitalization of user-entered names
View NameCase.cs
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 / gist:4154289
Created November 27, 2012 13:46
Redis Crashes
View gist:4154289

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 / gist:4197573
Created December 3, 2012 19:59
GCC replacement of hard-coded null %s parameter
View gist:4197573
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
mqudsi / magic.js
Last active November 6, 2015 23:48
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 / spawntest.c
Last active March 5, 2018 01:33
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
mqudsi /
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) };
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.
View menu.lst
# 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
default 0
timeout 10
mqudsi / StreamSequence.cs
Created April 29, 2020 19:17
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 / JsonRequest.cs
Created April 29, 2020 19:23
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 / WebView2Extensions.cs
Last active January 13, 2021 05:44
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)