Skip to content

Instantly share code, notes, and snippets.

@yspreen
yspreen / DictionaryKeyPath.swift
Last active November 30, 2022 22:41 — forked from dfrib/DictionaryKeyPath.swift
Swift: Reading and writing to (possible) nested dictionaries for a given key path, using a recursive approach
/*
Copyright 2022 @yspreen
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@kaustav-das
kaustav-das / XoRoRNG.cs
Last active December 6, 2020 09:13
xoroshiro128+ (named after its operations: XOR, rotate, shift, rotate) is a pseudorandom number generator intended as a successor to xorshift+. This is a direct C# port, mainly for Unity development, of the algorithm written by David Blackman and Sebastiano Vigna
/* Written in 2016 by David Blackman and Sebastiano Vigna (vigna@acm.org)
To the extent possible under law, the author has dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>. */
/**
* A port of Blackman and Vigna's xoroshiro128+ generator to C# for Unity Development.
* This is a direct rewrite from the JAVA implementation by SquidPony.
* <br>
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active July 12, 2024 03:33
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

@tomekw
tomekw / test_channel_spec.rb
Last active January 10, 2022 20:51
Unit testing ActionCable channels with RSpec
# app/channels/hello_channel.rb
class HelloChannel < ActionCable::Channel::Base
def say_hello(data)
times_to_say_hello = data.fetch("times_to_say_hello")
hello = "Hello, #{current_profile.name}!"
times_to_say_hello.times do
ActionCable.server.broadcast(current_profile.id, hello)
end
end
var buffer = null,
bufferContext = null;
//null => not yet checked
var multiplyDetected = null;
function isMultiplySupported() {
if (multiplyDetected === null) { //we haven't checked yet
if (!buffer) { //shared buffer...
buffer = document.createElement("canvas");
@jareware
jareware / SCSS.md
Last active July 1, 2024 09:25
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

@onedayitwillmake
onedayitwillmake / THREESketch.html
Created September 2, 2011 01:49
THREE.JS sketch template
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="lib/three.js/build/Three.js"></script>
<script type="text/javascript" src="lib/three.js/examples/js/Detector.js"></script>
<script type="text/javascript" src="lib/three.js/examples/js/RequestAnimationFrame.js"></script>
<script type="text/javascript" src="lib/three.js/examples/js/Stats.js"></script>
<script type="text/javascript" src="js/Sketch.js"></script>
@getify
getify / gist:801962
Created January 29, 2011 16:24
explaining __proto__ in prototypal inheritance
function A() {}
var a = new A();
function B() {
function F(){}
F.prototype = a;
return new F();
}
var b = new B(); // `b` now inherits from `a` (*not* `A`)
@banksean
banksean / perlin-noise-classical.js
Created February 15, 2010 10:00
two Perlin noise generators in javascript. The simplex version is about 10% faster (in Chrome at least, haven't tried other browsers)
// Ported from Stefan Gustavson's java implementation
// http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf
// Read Stefan's excellent paper for details on how this code works.
//
// Sean McCullough banksean@gmail.com
/**
* You can pass in a random number generator object if you like.
* It is assumed to have a random() method.
*/
@bellbind
bellbind / texture.html
Created October 22, 2009 11:19
[WebGL] Texture example by 2d canvas
<!DOCTYPE html>
<html>
<head>
<script>//<!--
// WebGL texture example
top.CanvasFloatArray = top.CanvasFloatArray || WebGLFloatArray;
var gl;
var program;