Skip to content

Instantly share code, notes, and snippets.

Eric Freed ForeverZer0

Block or report user

Report or block ForeverZer0

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ForeverZer0
ForeverZer0 / ReshapeWindow.cs
Last active Jun 5, 2018
[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 / Color.cs
Last active Jun 5, 2018
[C#] RGBA Color structure using a vector
View Color.cs
#region MIT License
// Color.cs is distributed under the MIT License (MIT)
//
// Copyright (c) 2018, Eric Freed
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@ForeverZer0
ForeverZer0 / NumericClamp.cs
Last active Jun 5, 2018
[C#] Extension method to clamp numeric types within a given range.
View NumericClamp.cs
public static T Clamp<T>(this T value, T min, T max) where T : struct, IComparable, IComparable<T>,
IConvertible, IEquatable<T>, IFormattable
{
if (value.CompareTo(min) < 0)
return min;
return value.CompareTo(max) > 0 ? max : value;
}
@ForeverZer0
ForeverZer0 / IsBetween.cs
Created Jun 5, 2018
[C#] Extension method to test if a numeric type is within a given range
View IsBetween.cs
public static bool IsBetween<T>(this T value, T min, T max) where T : struct, IComparable, IComparable<T>,
IConvertible, IEquatable<T>, IFormattable
{
return value.CompareTo(min) >= 0 && value.CompareTo(max) <= 0;
}
View suppress warning.rb
module Kernel
def suppress_warning
return unless block_given?
verbosity = $VERBOSE
$VERBOSE = nil
yield
$VERBOSE = verbosity
end
end
@ForeverZer0
ForeverZer0 / extract.rb
Created Jul 14, 2018
Unpacks a tar.gz file using Ruby, with symbolic-link and long name support
View extract.rb
require 'rubygems/package'
require 'zlib'
TAR_LONGLINK = '././@LongLink'
tar_gz_archive = '/path/to/archive.tar.gz'
destination = '/where/extract/to'
Gem::Package::TarReader.new( Zlib::GzipReader.open tar_gz_archive ) do |tar|
dest = nil
tar.each do |entry|
@ForeverZer0
ForeverZer0 / libpng.c
Last active Aug 5, 2018
Basic PNG read/write example using libpng.
View libpng.c
/*
* A simple libpng example program
* http://zarb.org/~gc/html/libpng.html
*
* Modified by Yoshimasa Niwa to make it much simpler
* and support all defined color_type.
*
* To build, use the next instruction on OS X.
* $ brew install libpng
* $ clang -lz -lpng15 libpng_test.c
@ForeverZer0
ForeverZer0 / String Replace Character.c
Created Aug 8, 2018
Function to do basic character replacement in a string.
View String Replace Character.c
char* replace_char(char* str, char find, char replace){
char *pos = strchr(str,find);
while (pos)
{
*pos = replace;
pos = strchr(pos,find);
}
return str;
}
@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 / lodepng.c
Created Aug 10, 2018
LodePNG source, fantastic source for cross-platform loading PNG images. Change .c to .cpp for C++ support.
View lodepng.c
/*
LodePNG version 20180809
Copyright (c) 2005-2018 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
You can’t perform that action at this time.