Skip to content

Instantly share code, notes, and snippets.

View quephird's full-sized avatar

danielle quephird

View GitHub Profile
@quephird
quephird / flamey_shader.frag
Created March 12, 2016 19:44
Just an experiment based on some of the stuff in chapter 7 of The Book of Shaders: http://thebookofshaders.com/07/
uniform vec2 u_resolution;
uniform float u_time;
void main(){
// Normalize the inbound pixel coordinates.
vec2 st = gl_FragCoord.xy/u_resolution.xy;
// Compute the position of the pixel with the origin as the center of the window.
vec2 pos = vec2(0.5)-st;
@quephird
quephird / fun-with-protocols-and-records.clj
Last active February 20, 2016 17:42
Inspired by some code I read this past week.
;; After seeing some code whereby a suite of function implementations for CRUD operations
;; for a set of object types were exactly the same except for the entity in question,
;; I wondered if there was a way to somehow share implementations. It's not quite OO
;; inheritance but this seems to do the job; I have no idea if this is considered
;; idiomatic Clojure code.
(ns fun-with-protocols-and-records)
;; Based on http://david-mcneil.com/post/1475458103/implementation-inheritance-in-clojure
;;
@quephird
quephird / Pi.hs
Created January 21, 2016 00:11
Just an exercise to compute pi based on random number generation
module Pi where
import Data.List.Split (chunksOf)
import System.Random (newStdGen, randoms)
randomTuples :: Int -> IO [(Float, Float)]
randomTuples n = do
seed1 <- newStdGen
seed2 <- newStdGen
let xs = randoms seed1 :: [Float]
(ns ellipses
(:require [quil.core :as q :include-macros true]
[quil.middleware :as m]))
(defn setup []
(q/background 0)
(q/stroke-weight 0.25)
(q/no-fill)
(q/color-mode :hsb)
(q/no-loop))
@quephird
quephird / pe13.clj
Last active December 10, 2015 22:46
This is a solution for ProjectEuler #13 that avoids "cheating" by resorting to BigInteger.
(defn solution [big-string]
(->> big-string
(clojure.string/split-lines) ; Break string into individual numbers
(map reverse) ; Reverse the digits in each
(map (fn [n] (map #(Integer/parseInt (str %)) n))) ; Turn all characters into actual ints
(apply map +) ; Sum each column of digits
(reduce (fn [[digits carry] n] ; Fold over the partial sums,
[(conj digits (rem (+ n carry) 10)) ; adding the current sum modulo ten to the list of digits
(quot (+ n carry) 10)]) [() 0]) ; and taking the quotient over ten as the carry
((fn [[digits carry]] (str carry (apply str digits)))) ; Convert back to a single string, last carry at the front.
#version 3.7;
global_settings { assumed_gamma 1.0 }
#include "colors.inc"
#include "glass.inc"
#include "textures.inc"
// Random color generator with moving seed
#declare My_seed = seed(now * 100000);
import Foundation
class Vehicle {
lazy var isWarmedUp: Bool = self.start()
var color: String?
var maxSpeed = 80 {
willSet(s) {
print("Changing max speed from \(s)...")
}
didSet(s) {
class Vehicle {
var color: String?
var maxSpeed = 80 {
willSet(s) {
print("Changing max speed from \(s)...")
}
didSet(s) {
print("to \(s)")
}
}
@quephird
quephird / Plot.purs
Last active September 17, 2015 23:16
Partial solution to third problem in first set of exercises in Chapter 9 of PureScript by Example
module Plot where
import Prelude (($), bind, return)
import Control.Monad.Eff (Eff(..))
import Data.List (List(..), toList)
import Data.Maybe (Maybe(..))
import Graphics.Canvas ( Canvas(..)
, Context2D(..)
, closePath