Skip to content

Instantly share code, notes, and snippets.

@klgraham
klgraham / hello-luajit.c
Last active April 27, 2024 14:45
A simple example of embedding LuaJIT in C
#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "luajit.h"
int main(int argc, char *argv[])
{
int status;
lua_State *L;
@klgraham
klgraham / factorial-luajit.c
Last active April 9, 2023 21:02
Example of using Lua C API to call a Lua function from C
#include <stdio.h>
#include <stdlib.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "luajit.h"
int main(int argc, char *argv[])
{
lua_State *L;
@klgraham
klgraham / RTX_3090_test_vs_AMD_5950x.py
Last active February 6, 2022 19:18
Testing RTX 3090 for deep learning
# Modified example from: https://huggingface.co/facebook/detr-resnet-50
from transformers import DetrFeatureExtractor, DetrForObjectDetection
from PIL import Image
import requests
import torch
print("GPU is available:", torch.cuda.is_available())
#device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

Keybase proof

I hereby claim:

  • I am klgraham on github.
  • I am klogram (https://keybase.io/klogram) on keybase.
  • I have a public key ASAH4w1M6pKVqmDTyHCQruuuVovVviDurs9-P8DblNSP7Qo

To claim this, I am signing this object:

@klgraham
klgraham / StreamReader.swift
Created April 29, 2017 05:03
A Swift class to read a text file line by line, without loading the entire file into memory
// Usage:
/*
if let aStreamReader = StreamReader(path: "/path/to/file") {
defer {
aStreamReader.close()
}
while let line = aStreamReader.nextLine() {
print(line)
}
}
class Perceptron {
var bias: Double
// weights[0] is the weight for the bias input
var weights: [Double]
init(numInputs: Int, bias: Double) {
self.bias = bias
self.weights = [Double]()
@klgraham
klgraham / gist:3768168
Created September 22, 2012 23:09
Call-by-name vs call-by-value in Scala
/* call-by-value means the parameters are evaluated left to
** right to determine their value before the function itself
** is evaluated
*/
def first(a: Int, b: Int): Int = a
first(3 + 4, 5 + 6) // will be reduced to first(7, 5 + 6), then first(7, 11), and then 7
/* call-by-name means the paramter is passed into the function
** as is. Parameter evaluation takes place after
** substitution
let testData = createData(100)
func evaluatePerceptron(p: Perceptron, testData: [PerceptronDataPair]) -> Double {
var correct = 0
for d in testData {
let prediction = p.feedForward(d.input)
if (prediction == d.output) {
correct += 1
}
}
@klgraham
klgraham / build-gcc.sh
Last active September 18, 2016 17:47 — forked from jeetsukumaran/build-gcc.sh
Build and Install GCC Suite from Scratch. Should only build static libraries.
#! /bin/bash
GCC_VERSION="5.2.0"
WORKDIR="$HOME/src/"
INSTALLDIR="/platform"
## NOTE: XCode must be installed (through App Store) and the following run to install command-line tools.
## THIS IS IMPORTANT! Among other things, it creates '/usr/include' and installs the system header files.
# xcode-select --install
@klgraham
klgraham / zip lists in Clojure
Created September 9, 2016 08:50
Implementation of a tail-recursive zip list function in Clojure.
(defn zipIndex [coll]
(loop [list coll
n 0
result []]
(if (empty? list)
result
(recur (rest list) (inc n) (conj result [n (first list)])))))