Skip to content

Instantly share code, notes, and snippets.

View icebreaker's full-sized avatar
👽
Code gardening!

Mihail Szabolcs icebreaker

👽
Code gardening!
View GitHub Profile
@rygorous
rygorous / gist:64a2965486e4458c279f
Created May 21, 2014 21:12
"Simple function to round up to the next power of 2"
//############################################################################
//## ##
//## Simple function to round up to the next power of 2. ##
//## ##
//############################################################################
static U32 Round_up_to_next_2_power( U32 value )
{
if ( value > 16 )
if ( value > 64 )
@dhh
dhh / test_induced_design_damage.rb
Last active November 2, 2024 00:52
This is an extraction from Jim Weirich's "Decoupling from Rails" talk, which explained how to apply the hexagonal design pattern to make every layer of your application easily unit testable (without touching the database etc). It only seeks to extract a single method, the EmployeesController#create method, to illustrate the design damage that's …
# Original Rails controller and action
class EmployeesController < ApplicationController
def create
@employee = Employee.new(employee_params)
if @employee.save
redirect_to @employee, notice: "Employee #{@employee.name} created"
else
render :new
end
79/02/28. 19.27.34.
PROGRAM DND1
00010 LET J4=1
00030 PRINT
00100 BASE 0
00110 LET X=0
00120 LET J=0
00130 LET K=0
00140 X1=0
@aras-p
aras-p / lambda.cpp
Last active September 24, 2019 02:40
Lambda art
// C++11 lambdas aren't terribly useful at producing art.
// Source below is valid C++11. VS2013 takes about a minute at it (Release config),
// reaches almost 4GB of memory usage and then gives a
//
// 1>ConsoleApplication1.cpp(34): fatal error C1001: An internal error has occurred in the compiler.
// 1> (compiler file 'msc1.cpp', line 1325)
// 1> To work around this problem, try simplifying or changing the program near the locations listed above.
// 1> Please choose the Technical Support command on the Visual C++
// 1> Help menu, or open the Technical Support help file for more information
// 1> This error occurred in injected text:
@Twinklebear
Twinklebear / main.cpp
Last active April 24, 2025 05:25
Example of render to texture with SDL2
#include <iostream>
#ifdef __linux__
#include <SDL2/SDL.h>
#elif defined(_WIN32)
#include <SDL.h>
#endif
const int WIN_WIDTH = 640;
const int WIN_HEIGHT = 480;
@jjb
jjb / gist:7389552
Last active December 22, 2024 15:58
Ruby 2.1 memory configuration

This all applies to Ruby 2.1. In some cases a setting is not available in 2.0, this is noted. There is also a different with 1.9, 1.8, and REE --- these are not noted.

All the relevant code is in https://github.com/ruby/ruby/blob/master/gc.c

RUBY_HEAP_MIN_SLOTS

default: 10000

The number of heap slots to start out with. This should be set high enough so that your app has enough or almost enough memory after loading so that it doesn't have to allocate more memory on the first request (althogh this probably isn't such a big deal for most apps).

(todo: figure out how big a slot is. i think the answer can be infered from this code.)

@markusfisch
markusfisch / README.md
Last active August 12, 2024 21:06
bash script to build a texture atlas with a little help from ImageMagick

mkatlas

[BASH][1] script to build a [texture atlas][2] for small/medium web sites/games. Requires [ImageMagick][3].

Usage

Basic

@JalfResi
JalfResi / revprox.go
Last active May 7, 2025 07:35
Simple reverse proxy in Go
package main
import(
"log"
"net/url"
"net/http"
"net/http/httputil"
)
func main() {
@hintjens
hintjens / zwtfpd.c
Created April 29, 2013 09:49
Minimal WTFP server in ZeroMQ
// Minimal WTFP server in 0MQ
#include "czmq.h"
static void *
wtfp_server (void *args)
{
zctx_t *ctx = zctx_new ();
void *router = zsocket_new (ctx, ZMQ_ROUTER);
int rc = zsocket_bind (router, "tcp://*:8080");
assert (rc != -1);
@attilam
attilam / RaycastWithTag.cs
Created November 14, 2012 14:31
Raycast for the closest object with a specific tag in Unity
public static bool RaycastWithTag(Ray ray, out RaycastHit hit, float distance, string tag, int layerMask = System.Int32.MaxValue) {
RaycastHit[] hits = Physics.RaycastAll(ray, distance, layerMask);
hit = new RaycastHit();
hit.distance = distance;
foreach(RaycastHit ahit in hits) {
if ( ahit.distance < hit.distance && ahit.transform.CompareTag(tag) ) {
hit = ahit;
}
}