Skip to content

Instantly share code, notes, and snippets.

View jfacoustic's full-sized avatar

Josh Mathews jfacoustic

View GitHub Profile
@jfacoustic
jfacoustic / sphere.cpp
Created September 29, 2016 02:11
Creates a vertex array to draw a sphere in OpenGL
#include <vector>
#include <cmath>
struct vec3 {
float x, y, z;
void set(float X, float Y, float Z)
{
x = X;
y = Y;
z = Z;
@jfacoustic
jfacoustic / mandelbrot.cu
Last active October 10, 2016 03:32
Mandelbrot Set calculated with CUDA: using resources from CUDA by Example at https://developer.nvidia.com/cuda-example
#include "../common/book.h"
#include "../common/cpu_bitmap.h"
#define DIM 1000
//From Wikipedia's article on the Mandelbrot Set:
__device__ int mandelbrot( int xa, int ya, float s, float xpos, float ypos) {
float x0 = s * (float) (DIM/2 -xa)/((float)DIM/2) + xpos;
float y0 = s * (float)(DIM/2 -ya )/((float)DIM/2) + ypos;
int m = 0;
@jfacoustic
jfacoustic / fibonacci.cpp
Last active July 3, 2017 02:19
Fibonacci with GMPXX; dynamic and traditional implimentations
#include <iostream>
#include <vector>
#include <ctime>
#include <gmpxx.h>
using namespace std;
mpz_class fibNorm(int n) {
if (n <= 1 ) return n;
return fibNorm(n-1) + fibNorm(n-2);
}
@jfacoustic
jfacoustic / vec_op.cu
Created December 22, 2019 17:32
Function Ptr Cuda Kernel
// CUDA function ptr example
// For basic vector operations
// Based on Chapter 2 of Programming Massively Parallel Processors 3rd Edition Kirk & Hwu
#include <stdio.h>
#include <cuda.h>
__global__ void addKernel(float * a, float * b, float * c, int n) {
int i = blockDim.x * blockIdx.x + threadIdx.x;
if(i < n) {
@jfacoustic
jfacoustic / interestCalculator.clj
Created January 1, 2020 19:16
Calculates interest in clojure
(defn calculate-interest
[apy base deposit months]
(if (= months 0)
( + base (* base apy))
(do (def newBase (+ base deposit))
(if (= (mod months 12) 0)
(calculate-interest apy (+ newBase (* newBase apy)) deposit (dec months))
(calculate-interest apy newBase deposit (dec months))))))
const cities = ['Tokyo', 'London', 'Rome', 'Donlon', 'Kyoto', 'Paris'].map(city => city.toLowerCase());
const matches = cities.reduce((acc, curr) => {
const double = curr + curr;
const match = [];
cities.forEach(city => {
if(double.includes(city)) {
match.push(city);
}
});
@jfacoustic
jfacoustic / split-string.lisp
Created September 4, 2020 17:20
Splits string by delimiter; default delimiter is \#space. (split-string "1 2 3 4") evaluates to ("1" "2" "3" "4").
(defun split-string (str &key (delimiter #\space))
(defun split-string-rec (str str-list delimiter-pos)
(if delimiter-pos
(let ((current (subseq str 0 delimiter-pos))
(remaining (subseq str (+ delimiter-pos 1) (length str))))
(split-string-rec remaining
(push current str-list)
(position delimiter remaining)))
(reverse (push str str-list))))
(split-string-rec str nil (position delimiter str)))
@jfacoustic
jfacoustic / simpsons.scm
Created October 11, 2020 15:21
1.29 SICP
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a) next b))))
(define (simpson-integral f a b n)
(let ((h (/ (- b a ) n)))
(define (term n)
(define y (f (+ a (* h n))))
(define (sum term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (+ result (term a)))))
(iter a 0))
@jfacoustic
jfacoustic / product.scm
Last active October 13, 2020 12:22
1.31 SICP (recursive)
(define (product term a next b)
(if (> a b)
1
(* (term a)
(product term (next a) next b))))
(define (inc x) (+ x 1))
(define (identity x) x)
(define (factorial n)