Skip to content

Instantly share code, notes, and snippets.

View willeccles's full-sized avatar
🖤
[[maybe_unused]]

Will Eccles willeccles

🖤
[[maybe_unused]]
View GitHub Profile
@willeccles
willeccles / anti-huge-blobs.c
Last active June 11, 2019 11:47
Using pointers to make huge blobs of data less painful to work with.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
The problem:
Say you have an array of N*M items. This is essentially
a 2D array, kept contiguously in memory (for example,
you have 15 devices, and their data is given to you
in a huge blob of 10 bytes each). We will call this
@willeccles
willeccles / userChrome.css
Last active June 12, 2019 16:50
My Firefox userChrome (made to match my startpage)
/* Look into using https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/theme
to make a custom theme. This would allow userChrome to be much smaller and less hacky. */
* {
/* Color of tabs when loading */
--tab-loading-fill: #808074 !important;
/* Background color of navbar */
--toolbar-bgcolor: #262626 !important;
/* Color of icons on navbar */
--lwt-toolbarbutton-icon-fill: #808074 !important;
@willeccles
willeccles / yapg.cpp
Last active May 30, 2019 23:25
Yet Another Password Generator in C++ with decent options.
#include <iostream>
#include <string>
#include <random>
#include <fstream>
#include <cstdlib>
#include "words.h"
#include <iomanip>
// github decided to ruin my indenting here don't hate me
const std::string CHARS_UPPER ("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
@willeccles
willeccles / 2018day8.cpp
Created May 21, 2019 20:33
Day 8 of 2018 advent of code. Loads input from file instead of stdin so that's very slow, and I put almost no effort into making it faster after it was done.
#include <chrono>
#include <cstdio>
#include <fstream>
#include <string>
#include <vector>
#include "tree.h" // for TreeNode
using namespace std::chrono;
@willeccles
willeccles / bftranspiler.cpp
Last active May 17, 2019 19:08
A C++ program that transpiles brainfuck code into usable C code.
#include <fstream>
#include <iostream>
#include <string>
#include <map>
#include <regex>
const std::map<char, std::string> bfinstructions{
{'>', "++ptr;"},
{'<', "--ptr;"},
{'+', "++*ptr;"},
@willeccles
willeccles / fget.go
Created April 9, 2019 00:40
A simple Go program to download a file and save it to the disk.
package main
import (
"fmt"
"io/ioutil"
"os"
"net/http"
"net/url"
)
@willeccles
willeccles / robots parser.cpp
Last active March 26, 2019 20:31
A simple parser for robots.txt files.
/* Tested with https://www.google.com/robots.txt */
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <utility> // for std::pair
#include <cstdio> // for std::printf
@willeccles
willeccles / Binary File Structs.md
Last active January 25, 2019 16:57
Writing structs to a binary file in C++

Why?

Why not? There are many times when saving a section of memory into a binary file (and being able to read it back) would be incredibly useful.

How?

You can do this using std::ofstream::write and std::ifstream::read, and you can open their files with the std::ifstream::binary flag.

Can you test it?

@willeccles
willeccles / alfred-kitty.scpt
Last active October 12, 2024 09:03
AppleScript for using Kitty in Alfred. This was made for bash, but can easily be made to work with any shell.
(* 2019-06-07: Added nohup and output redirection to fix a bug with "Open Terminal here" feature.
Thanks to @fools-mate for bringing the issue to my attention. *)
on alfred_script(q)
do shell script "cd ~; nohup /Applications/kitty.app/Contents/MacOS/kitty /bin/bash -c \"source ~/.bashrc && " & q & ";/bin/bash\" > /dev/null 2>&1 &"
end alfred_script
@willeccles
willeccles / inplaceswap.cpp
Created November 13, 2018 16:16
Swap two integer values without using a temporary value, using no extra memory.
#include <cstdio>
int main(void) {
int a = 5; // 0b0101
int b = 11; //0b1011
std::printf("Before swap:\na: %d\nb: %d\n", a, b);
// perform the swap
a ^= b; // a now = 0b1110