Skip to content

Instantly share code, notes, and snippets.

@studoot
studoot / detect-proxy-windows.cpp
Created July 5, 2022 13:39
Detect 'IE' proxy configuration for a URL on Windows.
#include "on_scope_exit.hpp"
#include <string>
#include <string_view>
#include <vector>
#include <Windows.h>
#include <stringapiset.h>
#include <winhttp.h>
@studoot
studoot / a.cpp
Created June 17, 2020 18:07
Issue with xxhash_cpp
#include "xxhash.hpp"
#include <iostream>
extern void process();
int main(int, char **)
{
process();
std::cout << "xxhash<32>(1) => " << xxh::xxhash<32>(std::array<uint32_t, 1>{1}) << std::endl;
}
@studoot
studoot / c_cpp_properties.json
Created September 5, 2018 14:12
Sample VSCode settings for using C++ in WSL
{
"configurations": [
{
"name": "WSL",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"includePath": [
"${command:extension.vscode-wsl-workspaceFolder}/**",
"/usr/include/**"
],
@studoot
studoot / repro.cmd
Created May 16, 2018 14:54
Repro case for GitKraken ignoring a file that it shouldn't
git init test-repo
echo *.c > .\test-repo\.gitignore
mkdir .\test-repo\subdir
type nul > .\test-repo\subdir\a.c
echo Expect to see .gitignore untracked, subdir/a.c ignored
git -C .\test-repo status --untracked=all --ignored=matching --short
echo !*.c > .\test-repo\subdir\.gitignore
echo Expect to see .gitignore, subdir/.gitignore and subdir/a.c all untracked
git -C .\test-repo status --untracked=all --ignored=matching --short
git -C .\test-repo add .\.gitignore .\subdir\.gitignore
@studoot
studoot / gist:f8d07002117868e92cf25f2e9c00b048
Created February 20, 2017 10:23
Log all branch merges to release branch since last 'version number' tag
# 'last(ancestors(branch(release)) & tag('re:^v[0-9.]+')):' - all commits since last tag matching '^v[0-9.]+'
# 'merge()' - just merge commits
# branch(release) - on the release branch
hg log -r "last(ancestors(branch(release)) & tag('re:^v[0-9.]+')): & merge() & branch(release)" --template "{node|short}: {desc|firstline}\n"
@studoot
studoot / get-version-from-git.ps1
Last active January 11, 2017 16:35
Powershell script to derive version information for C, C++ or F# from the extant git or Mercurial repository
param (
[string]$directory = $PSScriptRoot,
[ValidateSet('c','C','c++','C++','f#','F#')]
[string]$language,
[string]$revision,
[string]$output,
[string]$tagPrefix = 'v'
)
$directory = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($directory)
@studoot
studoot / test.fsx
Last active December 1, 2016 10:47
Bad word filter (challenge at https://www.codeproject.com/questions/1157796/coding-challenge-bad-word-filter) implementation in F#
open Printf
open System
open System.Diagnostics
open System.Text
open System.Text.RegularExpressions
type System.String with
member s.SplitAt(index) =
let lengthToUse = min index s.Length
(s.Substring(0, lengthToUse), s.Substring(lengthToUse))
@studoot
studoot / rustfmt-import-combiner-tests.rs
Created July 29, 2016 10:49
Tests for combining Rust imports, with a view to incorporating into rustfmt
#[test]
fn combine_glob_and_child() {
assert_eq!(combine_imports(&(vec![&ViewPath::from("a::b::c"),
&ViewPath::from("a::b::*")])),
vec![ViewPath::from("a::b::*")]);
assert_eq!(combine_imports(&vec![&ViewPath::from("a::b::c"),
&ViewPath::from("a::b::*"),
&ViewPath::from("a::b as x")]),
vec![ViewPath::from("a::b as x"), ViewPath::from("a::b::*")]);
assert_eq!(combine_imports(&vec![&ViewPath::from("a::b::c"),
module A where
import Control.Monad
-- Data types...
--
-- class Residence {
-- var numberOfRooms: Int
-- }
data Residence = Residence { rooms :: Int } deriving (Show)
@studoot
studoot / making-bitsets.cpp
Created July 1, 2014 11:43
Making bitsets with variadic templated functions
#include <bitset>
#include <iostream>
using std::bitset;
namespace detail
{
// Create a bitset from bools (or things convertible to bool). The first bool is the high-order
// bit, the size of the bitset determined by the size of the parameter pack.
template<class... Args>
bitset<sizeof...(Args)> make_bitset(Args const&... args)