Skip to content

Instantly share code, notes, and snippets.

View corysabol's full-sized avatar

Cory Sabol corysabol

View GitHub Profile
@corysabol
corysabol / godot_planet_gen.gd
Created October 20, 2020 17:16
Crappy code to generate a small low poly procedural planet. This script won't work on it's own and I'm certain it's broken right now, but maybe it can help sombody.
tool
extends Spatial
var radius = 0.5 # Using 2 for now, since that's the default size of the PlaneMesh object.
# Resolution is the number of squares which our faces have - i.e. r=64 -> 64x64 faces.
export(int) var resolution = 3
# What data do we need to track?
var meshInst
var triangleIndices = [] # [Vector3] - each element represents the 3 indices which make up a face triangle
var vertices = [] # [Vector3] - each element represents the spatial point that is a vertex
@corysabol
corysabol / unixhttpc.go
Created November 15, 2018 05:43 — forked from teknoraver/unixhttpc.go
HTTP over Unix domain sockets in golang
package main
import (
"context"
"flag"
"fmt"
"io"
"net"
"net/http"
"os"
@corysabol
corysabol / FindWeekday.hs
Last active November 5, 2016 22:39
Find the day of the week that a given date would fall on in the Gregorian calendar. (It's disgusting, but it's my own solution!)
module FindWeekday where
-- The ordering of this has to be weird
-- due to the result of modding the number of days
-- the date has.
-- This is because if we mod a number of days that is
-- evenly divisble by 7 we get 0 which would not be the
-- correct index of the day, so just shift the list of
-- days to fit with this skewing as seen below.
daysOfWeek :: [String]
/* find the sum of all the even fibonacci numbers less that 4 million */
#include <iostream>
// We need to first calculate the fibonacci numbers up to some bound
// This is going to be hard to do as elegantly or as efficiently as in Haskell
// Let's first define a funciton to quickly calculate the nth fib num
int nth_fib_r (int prev, int val, int n) {
-- This is some pretty cool math trickery
-- I cannot take credit for coming up with it.
-- Thanks random stack overflow user <3
rev_int :: Int -> Int
rev_int 0 = 0
rev_int n = mod n 10 * 10^place + rev_int(div n 10)
where
n' = fromIntegral n
place = (floor . logBase 10) n'
@corysabol
corysabol / palindrome.clj
Created April 21, 2016 03:41
A simple way to detect a palindrome in clojure by using (into) to reverse the string. There are probably better ways to do this. Also, this is useless... :^|
;; Author sible777
;; Why? I dunno I was bored and in the process
;; of learning clojure...
(ns coolstuff)
;; Detect if a string is a palindrome.
;; True if it is false otherwise.
(defn palindrome [string]
(if (= (seq string) (into '() (seq string)))