Skip to content

Instantly share code, notes, and snippets.

@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)
}
}
@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)])))))
@klgraham
klgraham / tail-recursive factorial
Created September 9, 2016 08:36
Tail-recursive factorial in Scala
def factorial(n: BigInt): BigInt = {
def fact(n: BigInt, result: BigInt): BigInt = {
if (n == 0) return result
else return fact(n - 1, result * n)
}
return fact(n, 1)
}
@klgraham
klgraham / Scala Loop-Recur for zipper
Created September 9, 2016 08:27
Example of tail-recursion in Scala that will not throw a StackOverflowError.
// Scala analog to Clojure's loop-recur construct
def loopRecur[A](index: Int, coll: Seq[A], zippedList: List[(Int, A)]): List[(Int, A)] = {
if (coll.isEmpty) return zippedList
else return loopRecur(index + 1, coll.tail, zippedList ++ List((index, coll.head)))
}
// Given a sequecne of items, returns a List of tuples of the form (item index, item)
def zipIndex[A](coll: Seq[A]): List[(Int, A)] = {
return loopRecur(0, coll, List.empty[(Int, A)])
}
@klgraham
klgraham / StringReversal.java
Created August 6, 2016 02:16
Recursive string reversal
package org.klgraham;
/**
* Created by klogram on 8/5/16.
*/
public class StringReversal {
public static String reverseStringIterative(final String s) {
StringBuilder sb = new StringBuilder();
@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 / hello-luajit.c
Last active August 8, 2024 18:56
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;