Skip to content

Instantly share code, notes, and snippets.

View define-private-public's full-sized avatar
🔮
(´・ω・`)

Benjamin Summerton define-private-public

🔮
(´・ω・`)
View GitHub Profile
@define-private-public
define-private-public / rotate_y_hit_snippet.nim
Created January 3, 2017 18:50
Peter Shirley Ray Tracing Mini-Books (in Nim); a code snippet that drove me nuts
method hit*(ry: rotate_y, r: ray, t_min, t_max: float, rec: var hit_record): bool=
# I thought this was copying the vec3 data, but it wasn't. It was copying the pointer...
var
origin = r.origin()
direction = r.direction()
# origin and direction are modified after this which caused the issue...
@define-private-public
define-private-public / stb_image_example.c
Last active December 30, 2016 21:33
stb_image-Nim blog post code snippets
#include "stb_image.h"
// Get the image data
int width, height, channels;
unsigned char *data = stbi_load("kevin_bacon.jpeg", &width, &height, &channels, STBI_default);
// Do what you want...
// Cleanup
stbi_image_free(data);
@define-private-public
define-private-public / laps.nim
Last active March 25, 2017 20:24
Nim stopwatch example usage
import stopwatch
from sequtils import map
var sw = Stopwatch()
# We're operating on a large image...
for y in countup(0, imgHeight - 1):
for x in countup(0, imgWidth -1 ):
sw.start()
# ... lengthy pixel operation
@define-private-public
define-private-public / nim_opengl_shader_example.nim
Last active September 26, 2019 05:59
An example of using OpenGL shaders (and indexed drawing) in Nim
# File: nim_opengl_shader_example.nim
# Author: Benjamin N. Summerton <define-private-public>
# Description: An example of how to use OpenGL shaders in Nim. Draws a simple
# rotating hexagon with 6 colors. Also uses indexed drawing.
#
# Uses this GLFW binding: https://github.com/rafaelvasco/nimrod-glfw, though if
# want to use SDL2, changing out the windowing should be simple.
#
# This was built on Linux using OpenGL ES 3. If you want to use a different
# OpenGL version then you will have to alter the shader source.
@define-private-public
define-private-public / Makefile
Created September 17, 2016 00:03
Porting a C/Berkeley Sockets application to C#
# Filename: Makefile
# Author: Benjamin N. Summerton <define-private-public>
# License: Unlicense (https://unlicense.org/)
# Change the value you're preferred c compiler (e.g. `clang` or `gcc`)
CC=clang
all: server client
server: server.c
@define-private-public
define-private-public / PingExample.cs
Last active November 21, 2022 23:57
Synchronous and Asynchronous (w/ callbacks) example usage of C#'s Ping class.
// Filename: PingExample.cs
// Author: Benjamin N. Summerton <define-private-public>
// License: Unlicense (http://unlicense.org/)
using System;
using System.Threading;
using System.Net.NetworkInformation;
namespace PingExample
{
@define-private-public
define-private-public / Arena.cs
Last active October 5, 2022 15:12
The classic game of Pong, that runs over UDP (uses MonoGame/XNA).
// Filename: Arena.cs
// Author: Benjamin N. Summerton <define-private-public>
// License: Unlicense (https://unlicense.org/)
using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.Collections.Concurrent;
@define-private-public
define-private-public / Block.cs
Last active May 1, 2023 06:30
UDP based file transfer in C#
// Filename: Block.cs
// Author: Benjamin N. Summerton <define-private-public>
// License: Unlicense (http://unlicense.org/)
using System;
using System.Text;
using System.Linq;
namespace UdpFileTransfer
{
@define-private-public
define-private-public / CompressionExample.cs
Last active October 28, 2023 17:56
Example of the DeflateStream & GZipStream in C#
// Filename: CompressionExample.cs
// Author: Benjamin N. Summerton <define-private-public>
// License: Unlicense (http://unlicense.org/)
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
namespace Compression
@define-private-public
define-private-public / GuessMyNumberGame.cs
Last active July 26, 2016 13:09
Text based games that go over TCP
// Filename: GuessMyNumberGame.cs
// Author: Benjamin N. Summerton <define-private-public>
// License: Unlicense (http://unlicense.org/)
using System;
using System.Net.Sockets;
using System.Threading;
namespace TcpGames
{