Skip to content

Instantly share code, notes, and snippets.

View redblobgames's full-sized avatar
🥰

Amit Patel redblobgames

🥰
View GitHub Profile
@redblobgames
redblobgames / .block
Last active October 17, 2016 23:00
which d3 apis do people use
license: mit
border: yes
scrolling: yes
@redblobgames
redblobgames / variant.h
Created April 30, 2016 17:20
mapbox::variant pattern matching
#include "variant/variant.hpp"
template<typename ...T> using variant = mapbox::util::variant<T...>;
namespace matchdetail {
template<typename C, typename Arg>
Arg lambda_argument(void(C::*)(const Arg&) const) {}
template<typename Other>
void lambda_argument(Other) {}
@redblobgames
redblobgames / dice.cpp
Created January 23, 2017 05:28
C++11 dice rolling syntax: write 2d6 dice roll as 2_d6 c++ syntax
#include <iostream>
#include <cstdlib>
int roll_dice(int numdice, int die) {
int total = 0;
for (int i = 0; i < numdice; i++) {
total += std::rand() % die;
}
return total;
}
@redblobgames
redblobgames / .block
Last active March 20, 2017 15:22
Mandelbrotch
license: mit
@redblobgames
redblobgames / huh.js
Created April 22, 2017 16:33
Befuddled
// I wrote wrong1 vs right1 to demonstrate automatic semicolon insertion. So far so good.
function wrong1(x) {
return
{
upper: x + 1
};
}
function right1(x) {
@redblobgames
redblobgames / .block
Created September 12, 2017 16:18
HTML Color Names (Relative Lightness, linear color space)
license: mit
#define M_TAU (2.0*3.1415926535897932384626433832795)
precision mediump float;
uniform float u_t, u_N, u_width, u_radius;
attribute vec2 a_wh;
varying vec2 v_texcoord;
void main () {
float w = a_wh.x; /* which "wedge" we're on */
float h = a_wh.y; /* will be 0 at center of circle and 1 at rim */
@redblobgames
redblobgames / svg-arrowhead.html
Created March 7, 2017 22:34
SVG arrowhead example
<!DOCTYPE html>
<html>
<svg width="80%" height="80%" viewBox="-100 -100 200 200">
<!-- Need this definition to make an arrowhead, from https://www.w3.org/TR/svg-markers/ -->
<defs>
<marker id="red-arrowhead" viewBox="0 0 10 10" refX="7" refY="5" markerUnits="strokeWidth" markerWidth="4" markerHeight="3" orient="auto">
<path d="M 0 0 L 10 5 L 0 10 z" stroke="none" fill="red"/>
</marker>
</defs>
@redblobgames
redblobgames / test-picojson-variant-tagged.cpp
Created May 17, 2018 22:06
traverse variant+picojson using tags for variants instead of integer indices
// Copyright 2018 Red Blob Games <redblobgames@gmail.com>
// https://github.com/redblobgames/cpp-traverse
// License: Apache v2.0 <http://www.apache.org/licenses/LICENSE-2.0.html>
#include "traverse.h"
#include "traverse-picojson.h"
#include "traverse-variant.h"
#include "traverse-picojson-variant-tagged.h"
#include "variant-util.h"
@redblobgames
redblobgames / .block
Last active July 31, 2018 04:03
Outside the box
license: apache-2.0
scrolling: yes
height: 900