Skip to content

Instantly share code, notes, and snippets.

@ForeverZer0
ForeverZer0 / main.c
Created February 25, 2020 16:48
Prime number generator
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
static struct option prime_opts[] =
{
{"count", required_argument, NULL, 'c'},
@ForeverZer0
ForeverZer0 / RemoveGitSubModule.md
Last active February 18, 2020 13:22
Completely remove/delete git submodule from project

Completely Remove Git Sub-Module

Two different methods to automate the process of removing a submodule from a git repo with a single command. Adapted from here.

NOTE: A commit is made during removal, so it is best to commit any other changes prior to executing the command.

Using as a script in your PATH (filename will be name of command)

  • Create a new file anywhere in your shell's search paths (i.e. ~/.local/bin)
  • Copy the following
@ForeverZer0
ForeverZer0 / exportsym.rb
Created February 17, 2020 03:15
Export formatted list of symbols defined in a C/C++ library
#!/usr/bin/env ruby
#==============================================================================
#
# Searches for a library either local or on the system and prints out a sorted
# list of all exported symbols found within it. (UNIX-like systems only)
#
# Useful for creating a wrapper/bindings for a C/C++ library.
#
# Example: exportsym tar
@ForeverZer0
ForeverZer0 / ConvertFileToResource.md
Created February 17, 2020 00:55
Converts any file to C char array to embed as resource.

Convert any file to formatted string of hex characters

#!/usr/bin/bash
hexdump -v -e '16/1 "_x%02X" "\n"' $1 | sed 's/_/\\/g; s/\\x  //g; s/.*/    "&"/'

The output can then be copied and assigned to a const char * in a header/source file and referenced as a normal string.

@ForeverZer0
ForeverZer0 / hex2char.sh
Created January 30, 2020 06:19
Convert a binary file into a string that can be stored in a C file as an embedded resource.
#!/usr/bin/bash
hexdump -v -e '16/1 "_x%02X" "\n"' $1 | sed 's/_/\\/g; s/\\x //g; s/.*/ "&"/'
@ForeverZer0
ForeverZer0 / OpenAL.cs
Last active January 26, 2020 17:43
Minimal bindings for OpenAL
using System;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
namespace MyNamespace
{
[SuppressUnmanagedCodeSecurity]
[SuppressMessage("ReSharper", "IdentifierTypo")]
@ForeverZer0
ForeverZer0 / libsndfile.cs
Created January 25, 2020 20:54
Minimal bindings for the libsndfile library.
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
namespace SndFile
{
[SuppressUnmanagedCodeSecurity]
@ForeverZer0
ForeverZer0 / libogg.cs
Created January 25, 2020 20:48
Minimal bindings of the libogg reference library.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Security;
// Referernce Source: https://xiph.org/vorbis/doc/libvorbis/reference.html
namespace OGG
{
[SuppressUnmanagedCodeSecurity]
@ForeverZer0
ForeverZer0 / hosts
Last active December 16, 2019 12:15
Block Spotify Ads
############## SPOTIFY ###################
127.0.0.1 media-match.com
127.0.0.1 adclick.g.doublecklick.net
127.0.0.1 www.googleadservices.com
127.0.0.1 pagead2.googlesyndication.com
127.0.0.1 googleads.g.doubleclick.net
127.0.0.1 pubads.g.doubleclick.net
127.0.0.1 securepubads.g.doubleclick.net
127.0.0.1 www.omaze.com
127.0.0.1 omaze.com
@ForeverZer0
ForeverZer0 / case_conversion.rb
Created September 18, 2018 22:16
snake_case, camelCase, and PascalCase extension methods for Ruby's String class.
class String
def snake_case
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
.tr("-", "_")
.downcase
end
def camel_case