Skip to content

Instantly share code, notes, and snippets.

Avatar

Eric Freed ForeverZer0

View GitHub Profile
@ForeverZer0
ForeverZer0 / ip2country.rb
Last active Aug 31, 2020
Ruby method to quickly get the country and country codes from a given IPv4 or IPv6 address using only standard library
View ip2country.rb
#!/usr/bin/env ruby
require 'json'
require 'net/http'
##
# Gets a hash containing the country of origin with a given IPv4 or IPv6 address.
#
# @param ip [String,#to_s] An IPv4 or IPv6 address, or an object that returns one with #to_s
#
@ForeverZer0
ForeverZer0 / timer.c
Created Aug 8, 2018
Cross-platform, drop-in, high resolution timer for C/C++ projects.
View timer.c
/* ----------------------------------------------------------------------- */
/*
Easy embeddable cross-platform high resolution timer function. For each
platform we select the high resolution timer. You can call the 'ns()'
function in your file after embedding this.
*/
#include <stdint.h>
#if defined(__linux)
# define HAVE_POSIX_TIMER
# include <time.h>
@ForeverZer0
ForeverZer0 / imgur_upload.rb
Last active Aug 29, 2020
Upload a file to Imgur with Ruby, using no external dependencies, only standard library.
View imgur_upload.rb
#!/usr/bin/env ruby
require 'base64'
require 'json'
require 'net/http'
##
# The Imgur client ID. Create your own at https://api.imgur.com/oauth2/addclient
CLIENT_ID = '3662c57963d1bdf'
@ForeverZer0
ForeverZer0 / ReshapeWindow.cs
Last active Aug 22, 2020
[C#][OpenGL] Maintain aspect ratio when resizing window
View ReshapeWindow.cs
/// <summary>
/// Reshapes the drawing are to maintain aspect ratio when the window is resized,
/// using a target pixel ratio to maintain, and applying "pillars" or "letterbox"
/// effect as needed, allowing the drawing context to shrink/grow uniformly.
/// </summary>
/// <param name="width">The new width of the window/drawing area to fit to.</param>
/// <param name="height">The new height of the window/drawing area to fit to.</param>
public void WindowReshape(int width, int height)
{
// Make the projection matrix active
@ForeverZer0
ForeverZer0 / Giuffre v. Maxwell - Links to the documents released on 07-30-2020 (which were under seal)
Created Jul 31, 2020
Giuffre v. Maxwell - Links to the documents released on 07-30-2020 (which were under seal)
View Giuffre v. Maxwell - Links to the documents released on 07-30-2020 (which were under seal)
@ForeverZer0
ForeverZer0 / ExtractTarGz.cs
Last active Jun 7, 2020
Use pure C# to extract .tar and .tar.gz files
View ExtractTarGz.cs
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace TarExample
{
public class Tar
{
@ForeverZer0
ForeverZer0 / GL.Delegates.cs
Created May 10, 2020
Generated C# bindings for OpenGL 3.3 (Core Profile)
View GL.Delegates.cs
using System;
using System.Runtime.InteropServices;
using System.Security;
// ReSharper disable InconsistentNaming
// ReSharper disable IdentifierTypo
namespace OpenGL
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
@ForeverZer0
ForeverZer0 / MeshLoader.cs
Created May 4, 2020
Simplified loader for creating a mesh from Wavefront OBJ (*.obj) format.
View MeshLoader.cs
/*
* MIT License
*
* Copyright (c) 2020 Eric Freed
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@ForeverZer0
ForeverZer0 / SphereMesh.cs
Last active May 3, 2020
Various mesh generation techniques for spheres.
View SphereMesh.cs
/*
* MIT License
*
* Copyright (c) 2020 Eric Freed
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@ForeverZer0
ForeverZer0 / RectPacker.cs
Created Apr 4, 2020
High-efficiency bin-packer implementation for 2D rectangles.
View RectPacker.cs
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
namespace MyNamespace
{
/// <summary>
/// Represents a rectangular box shape.
/// </summary>
You can’t perform that action at this time.