Skip to content

Instantly share code, notes, and snippets.

View sjqtentacles's full-sized avatar

sjqtentacles

View GitHub Profile
@sjqtentacles
sjqtentacles / fennel-func
Created July 29, 2021 21:12
functional programming library for Fennel lisp dialect for use with Love2D and Lua
(fn table-insert [tab val]
(var t tab)
(table.insert t val)
t)
(fn table-remove [tab indx]
(var t tab)
(table.remove t indx)
t)
@sjqtentacles
sjqtentacles / utils.scm
Created July 17, 2021 04:50
biwascheme utilities for python-style dictionaries, plus a few other handy functions
(define (zip lis1 lis2)
(if (and (not (equal? lis1 '())) (not (equal? lis2 '())))
(cons (cons (car lis1) (car lis2)) (zip (cdr lis1) (cdr lis2)))
'()))
(define (take ls count)
(if (and (> count 0) (not (equal? ls '())))
(cons (car ls) (take (cdr ls) (- count 1)))
'()))
@sjqtentacles
sjqtentacles / flatten_ints.erl
Created February 26, 2018 22:08
flatten an array of arbitrarily nested arrays of integers into a flat array of integers
-module(flatten_ints).
-export([flatten/1, test/0]).
% I also wrote a scala one from the prolog 99 problems set - but this was a while back
% located here: https://github.com/Nixonite/scala-99/blob/master/p07.scala
% base cases here
flatten([]) -> [];
flatten([[]|T]) -> flatten(T);
@sjqtentacles
sjqtentacles / mat2csvUsingPython.py
Created September 13, 2015 23:32
Converting .mat to .csv using python
import scipy.io
import numpy as np
data = scipy.io.loadmat("subject.mat")
for i in data:
if '__' not in i and 'readme' not in i:
np.savetxt(("filesforyou/"+i+".csv"),data[i],delimiter=',')
@sjqtentacles
sjqtentacles / gist:67c712e4893d2a3669d4
Last active August 29, 2015 14:20
Calinski Harabasz Index function
def CH_index(X, labels, centroids):
#X being a pandas dataframe, so X = dataframe.values
#labels being the (KMeans(n_clusters=i).fit(X)).labels_
#centroids being the KMeans centroid values of a fitted kmeans model
'''
https://github.com/scampion/scikit-learn/blob/master/scikits/learn/cluster/__init__.py
'''
mean = np.mean(X,axis=0)
B = np.sum([ np.sum(labels==i)*(c - mean)**2 for i,c in enumerate(centroids)])
W = np.sum([ (x-centroids[labels[i]])**2 for i, x in enumerate(X)])