Skip to content

Instantly share code, notes, and snippets.

@staafl
staafl / gist:55fe3b658cdc30f4becca548ce35125b
Last active February 1, 2020 00:34
OpenGL shader chaining using FrameBuffer woes
// setting up two shaders
bufferPass = setupRenderPass("bufferA.frag", 1 /* toBuffer */)
imagePass = setupRenderPass("image.frag", 0 /* toBuffer */)
// inside setupRenderPass
renderPass setupRenderPass(shaderFile, toBuffer) {
// ...
renderPass.prog = getShader(shaderFile);
renderPass.iChannel0 = glGetUniformLocation(renderPass.prog, "iChannel0");
@staafl
staafl / longestSubstringWithoutMoreThanNRepeatingCharacters.js
Last active July 13, 2019 08:26
longestSubstringWithoutMoreThanNRepeatingCharacters
// Given a string, find the length of the longest substring without (more than n) repeating characters.
function longestSubstringWithoutMoreThanNRepeatingCharacters(str, n) {
// lastSeenByCount[2]['s'] = third place we've seen 's' so far
let lastSeenByCount = [...Array(n).keys()].map(_ => ({}));
let currentLength = 0;
let maxLength = 0;
let maxLengthStart = 0;
let startingFrom = 0;
(defn problem26-fibs [x]
(let [fibs
((fn fibs [so-far]
(lazy-seq
(fibs
(cons (+ (first so-far) (second so-far)) so-far)
)))
'(1 1))]
(take x fibs)))
@staafl
staafl / extract-pattern-from-file.cs
Last active August 29, 2015 14:10
extract-pattern-from-file.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class Program
{
static int Main(string[] args)
> let rec gcd = function
- | a 0 -> a
- | a b -> gcd b (a % b);;
| a 0 -> a
----^
stdin(29,5): error FS0039: The pattern discriminator 'a' is not defined
let rec loop k =
match () with
| _ when (x % k) = 0 && (x / k >= 100) && (x / k) <= 999 -> true
| _ when (float k) > System.Math.Sqrt (float x) -> false
| _ -> loop (k + 1)
@staafl
staafl / gist:7128171
Last active December 26, 2015 09:19
(defproject tst "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"],
[prxml "1.3.1"]],
:main tst.core/foo)
(use 'clojure.contrib.prxml)
// what's printed?
Console.WriteLine("null is object: " + (null is object));
Console.WriteLine("null is IDisposable: " + (null is IDisposable));
Console.WriteLine("null is int: " + (null is int));
Console.WriteLine("null is int?: " + (null is int?));
Console.WriteLine("null is Func<int>: " + (null is Func<int>));
Console.WriteLine("null is FileMode: " + (null is FileMode));
Console.WriteLine("0 is FileMode: " + (0 is FileMode));
Console.WriteLine("0 is int?: " + (0 is int?));
Console.WriteLine("short over short: " + (((short)10)/((short)5)).GetType());