Skip to content

Instantly share code, notes, and snippets.

@jgcoded
jgcoded / winrt-sse.cpp
Last active June 26, 2023 06:25
C++/WinRT Server-sent Events Implementation
// These should be in pch.h
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Web.Http.h>
#include <winrt/Windows.Web.Http.Headers.h>
#include <winrt/Windows.Web.Http.Filters.h>
#include <winrt/Windows.Storage.Streams.h>
#include <iostream>
#include <Windows.h>
@jgcoded
jgcoded / rbtree.c
Last active August 21, 2022 04:13
Red-Black Tree
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
/*
*
* 1: every node is either red or black
* 2: root is black
* 3: every leaf (NIL) is black
* 4: if a node is red then both its children are black
@jgcoded
jgcoded / DisjointSetsForest.c
Created August 1, 2022 05:05
Disjoint-Sets Forest with path-compression and union-by-rank
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct Set {
struct Set* parent;
int value;
int rank;
} Set;
@jgcoded
jgcoded / window.cpp
Last active September 18, 2022 06:40
C++ class abstraction of Win32 windows
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <winrt/Windows.Foundation.h>
#include <unordered_map>
#include <functional>
#include <CommCtrl.h>
@jgcoded
jgcoded / chat.rs
Last active February 22, 2022 03:33
Rust chat app via UDP Broadcast packets
use std::{collections::HashSet, net::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr, UdpSocket}};
use std::thread;
use std::sync::Arc;
use std::time;
use std::error::Error;
use std::io;
use std::sync::mpsc;
use thread::sleep;
use std::sync::atomic::{AtomicBool, Ordering};
use time::Duration;
@jgcoded
jgcoded / joinmanytomany.sql
Last active April 18, 2021 20:35
Learning SQL Joins On Many-To-Many Relationships
/*
Usage:
$ sqlite3 test.db
>.read test.sql -- Home - Recent Page
Get Concepts for a particular user
SELECT * FROM EntityConcept WHERE EntityID=0;
Get Users with a Particular Concept
SELECT * FROM EntityConcept WHERE ConceptID=1;
@jgcoded
jgcoded / MusicBeep.cpp
Last active July 25, 2018 06:32
Code that uses music theory to play scales and make chords
// MusicBeep.cpp : music theory code to make scales and chords
//
#include "stdafx.h"
#include <Windows.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
@jgcoded
jgcoded / compiletime-strings.hpp
Created June 24, 2017 08:17
C++ Compile time conversion of a number to a string
/*!
This file contains code to convert unsigned integers to strings
at compile-time, and then modify those strings include more
information.
One use case is to convert library MAJOR, MINOR, and PATCH
numbers into a custom string (see below).
Other types like signed integers and floats can be added
with template specializition on the converter struct.
@jgcoded
jgcoded / trie.cpp
Created May 27, 2017 23:56
Autocomplete word suggestions using a trie
/*!
A simple command-line application that provides word completion suggestions.
The application assumes that a list of words is provided by the system.
On Ubuntu, the application attempts to read from the /usr/share/dict/words
file installled by the wamerican package.
Once the trie is built, word completion suggestions is obtained via a
recursve method that collects words as the trie is traversed.
*/
@jgcoded
jgcoded / wxHelloWorld.cpp
Created May 2, 2017 18:10
Sample WxWidgets 3.0.3 Hello World application
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/msgdlg.h>
#include <wx/log.h>
enum
{
ID_Hello = 1