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 / 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(
@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 / profile.svg
Last active September 3, 2019 19:50
Profile of javac 11 compiling 155 classes, 42000 loc
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@spullara
spullara / bitsquatting.log
Last active September 18, 2018 20:24
Bit Squatting
/var/log/httpd/cloudfront_log:"d1wh43egtz3cgo.clgudfront.net" 116.12.133.146 - - [22/Aug/2011:00:32:55 +0000] "GET /bulk_images/69632/banner-small-planet-holiday-batam.jpg HTTP/1.1" 404 348 "http://36ohk6dgmcd1n.yom.mail.yahoo.net/om/api/1.0/openmail.app.invoke/36ohk6dgmcd1n/4/1.0.35/sg/en-SG/view.html" "Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20100101 Firefox/6.0"
/var/log/httpd/cloudfront_log:"d3dtik4dz1nejo.cloedfront.net" 208.80.194.29 - - [22/Aug/2011:17:27:58 +0000] "GET /75.html HTTP/1.0" 404 300 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; YPC 3.0.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"
/var/log/httpd/cloudfront_log:"doug1izaerwt3.cloutfront.net" 76.94.217.102 - - [23/Aug/2011:05:02:10 +0000] "GET /icons/apache_pb2.gif HTTP/1.1" 200 1797 "http://doug1izaerwt3.cloutfront.net/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"
/var/log/httpd/cloudfront_log:"doug1izaerwt3.cloutfront.net" 76.94.217.102 - - [23/Aug/2011:05:02:10 +00
@spullara
spullara / App.java
Created July 30, 2018 18:48
Comparing Java Fibers vs ForkJoinPool - performance of FJP is 60% faster than Fibers are currently and use less memory
package com.sampullara.fibers;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
public class App {
public static final int NUM = 100_000_000;
Timer timer = mr.timer("jvm.pausetime");
new Thread(() -> {
while (true) {
long start = System.nanoTime();
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// ignore
}
long diff = System.nanoTime() - start;
@spullara
spullara / main.swift
Created March 24, 2018 22:08
Swift implementation of my interview code
func render(text: String, entities: Set<Entity>) -> String {
let entityArray = Array(entities).sorted()
var sb = String()
var pos = 0
var posIndex = text.startIndex
for entity in entityArray {
let startIndex = text.index(posIndex, offsetBy: entity.start - pos)
sb.append(contentsOf: text[posIndex ..< startIndex])
sb += entity.html
@spullara
spullara / gist:6489b1704e51d75190f94be3ead3154a
Created March 20, 2018 18:41
Potential JShell use case
-> /resolve com.fasterxml.jackson.core:jackson-databind:2.8.7
| Path /Users/sam/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.8.7/jackson-databind-2.8.7.jar added to classpath
| Path /Users/sam/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0.jar added to classpath
| Path /Users/sam/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.7/jackson-core-2.8.7.jar added to classpath
-> var mf = new com.fasterxml.jackson.databind.MappingJsonFactory()
| Added variable mf of type com.fasterxml.jackson.databind.MappingJsonFactory with initial value com.fasterxml.jackson.databind.MappingJsonFactory@1a482e36
-> var jp = mf.createJsonParser("{\"foo\":\"bar\"}")
| Added variable jp of type com.fasterxml.jackson.core.JsonParser with initial value com.fasterxml.jackson.core.json.ReaderBasedJsonParser@689604d9
@spullara
spullara / SlowInputStream.java
Created November 15, 2017 20:47
Read it more slowly so as not to overload the system
public class SlowInputStream extends BufferedInputStream {
private final long start;
private final double rate;
private long read;
@Override
public synchronized int read(byte[] b, int off, int len) throws IOException {
maybeWait();
int bytes = super.read(b, off, len);
read += bytes;