Skip to content

Instantly share code, notes, and snippets.

View spullara's full-sized avatar
💭
The mess cannot go into the program, it piles up around the programmer.

Sam Pullara spullara

💭
The mess cannot go into the program, it piles up around the programmer.
View GitHub Profile
@spullara
spullara / chat
Last active March 26, 2024 19:19
Use this command to get suggestions on how to do things on the command line.
#!/bin/bash
TOKEN=< OpenAI token from https://platform.openai.com/account/api-keys >
PROMPT="You are the best at writing shell commands. Assume the OS is Ubuntu. I want you to respond with only the shell commands separated by semicolons and no commentary. Here is what I want to do: $@"
RESULT=`curl -s https://api.openai.com/v1/chat/completions \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $TOKEN" \
-d "{
\"model\": \"gpt-3.5-turbo\",
\"messages\": [{\"role\": \"user\", \"content\": \"$PROMPT\"}]
}" | jq '.choices[] | .message.content' -r`
@spullara
spullara / ReflectTest.java
Created December 25, 2011 22:31
Invokedynamic all in one example
package indy;
import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Constructor;
import org.objectweb.asm.ClassWriter;
@spullara
spullara / generate.py
Last active January 1, 2024 11:18
CLI based embedding search using OpenAI
import openai
import tiktoken
import os
from openai.embeddings_utils import get_embedding
openai.organization = os.environ.get("OPENAI_ORG")
openai.api_key = os.environ.get("OPENAI_API_KEY")
# Global variables
tokenizer = tiktoken.get_encoding(
#!/bin/sh
# simple script for turning a jar with a Main-Class
# into a stand alone executable
# cat [your jar file] >> [this file]
# then chmod +x [this file]
# you can now exec [this file]
commandToRun="$(printf "%q " "$@")"
if test "$commandToRun" = "'' "; then
eval "exec java -Xmx1G -jar $0"
else
package com.sampullara;
import java.util.ArrayList;
import java.util.List;
import java.util.Spliterator;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@spullara
spullara / FDBCount.java
Last active February 19, 2023 17:36
Server-side count of keys for FoundationDB. Still has to scan the complete database. Modified with input from the FDB team to use getKey.
// 1) Stride through the database using KeySelectors until you pass the end of the database
// 2) Then, back off until you find the last key
final AtomicBoolean retry = new AtomicBoolean();
Function<Transaction, Long> function = new Function<Transaction, Long>() {
private long start = System.currentTimeMillis();
private long count = 0;
private int offset = 1000000;
private KeySelector keySelector = KeySelector.firstGreaterOrEqual(new byte[0]);
private boolean narrowing = false;
@spullara
spullara / Rated.java
Last active August 7, 2021 05:27
Output a star rating using Java backing code.
public class Rated {
public Rated(JsonNode node) {
starRating = node.get("rating").intValue();
}
int starRating;
class Star {
boolean active;
package spullara.util.concurrent;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
@spullara
spullara / Pivot.java
Last active September 21, 2020 14:15
JDK 8 experiment where I recreate Excel pivot tables for collections of structured objects.
@Test
public void testPivotTable() {
List<Row> rows = new ArrayList<>();
rows.add(new Row("East", "Boy", "Tee", 10, 12.00));
rows.add(new Row("East", "Boy", "Golf", 15, 20.00));
rows.add(new Row("East", "Girl", "Tee", 8, 14.00));
rows.add(new Row("East", "Girl", "Golf", 20, 24.00));
rows.add(new Row("West", "Boy", "Tee", 5, 12.00));
rows.add(new Row("West", "Boy", "Golf", 12, 20.00));
rows.add(new Row("West", "Girl", "Tee", 15, 14.00));
@spullara
spullara / pom.xml
Created April 19, 2016 20:51
How to organize a mono-java-repo with Maven.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yourpackage</groupId>
<artifactId>parentartifactofeverything</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>module1</module>
<module>module2</module>