Skip to content

Instantly share code, notes, and snippets.

@B-R-P
B-R-P / calculator.java
Last active February 21, 2023 14:23
Calculator GUI in java
import javax.swing.*;
import java.awt.event.*;
import java.awt.GridLayout;
import java.util.*;
class CalculatorFrame extends JFrame implements ActionListener{
JTextField screen;
JPanel buttonPanel;
String operation;
Integer result;
List<String> operations = Arrays.asList("+","-","*","/","%","C","=");
@B-R-P
B-R-P / traffic.java
Last active February 21, 2023 11:58
Traffic Light Simulation
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Light extends JPanel implements ActionListener {
private JRadioButton r1,r2,r3;
private Color color1,color2,color3,bgcolor;
Light() {
setBounds(0, 0, 640, 480);
r1 = new JRadioButton("Red");
@B-R-P
B-R-P / docs.txt
Created April 2, 2023 07:25
Java docs in Twitter Algorithm
This file has been truncated, but you can view the full file.
ann\src\main\java\com\twitter\ann\faiss\NativeUtils.java
NativeUtils
unpackLibraryFromJarInternal(String path) -> File
unpackLibraryFromJar(String path) -> void
Unpack library from JAR into temporary path
*
@param path The path of file inside JAR as absolute path (beginning with
'/'), e.g. /package/File.ext
@throws IOException If temporary file creation or read/write
operation fails
@B-R-P
B-R-P / scaladocs.txt
Created April 2, 2023 13:21
scala declarations in Twitter Algorithm
This file has been truncated, but you can view the full file.
.\ann\src\main\scala\com\twitter\ann\annoy\AnnoyCommon.scala
object AnnoyCommon
def apply(scalaParams: AnnoyRuntimeParams): ServiceRuntimeParams
def invert(thriftParams: ServiceRuntimeParams): Try[AnnoyRuntimeParams] =
thriftParams match
class AnnoyRuntimeParams(
/* Number of vectors to evaluate while searching. A larger value will give more accurate results, but will take longer time to return.
@B-R-P
B-R-P / summarizer.py
Last active September 17, 2023 13:54
Summarize text using nltk and numpy
import nltk
import numpy as np
from nltk.stem import PorterStemmer
from nltk.text import TextCollection
from nltk.corpus import stopwords as sw
from nltk.tokenize import word_tokenize, sent_tokenize
stem = PorterStemmer().stem
nltk.download('stopwords')
stopWords = sw.words('english')
normalize = lambda array: np.divide(array, np.max(array))
@B-R-P
B-R-P / q-star.py
Created November 24, 2023 19:07
Q-Star Reinforcement Learning for Grid Navigation
import numpy as np
# Define constants for the grid world
GRID_SIZE = 5
NUM_ACTIONS = 4
NUM_EPISODES = 500
MAX_STEPS_PER_EPISODE = 50
# Define states (representing positions on the grid)
STATES = [(i, j) for i in range(GRID_SIZE) for j in range(GRID_SIZE)]
@B-R-P
B-R-P / score_sentences.js
Last active January 27, 2024 13:50
Score each sentence in a text using gzip
import zlib from 'zlib';
import sbd from 'sbd';
function calculateZScore(arr) {
const mean = arr.reduce((sum, value) => sum + value, 0) / arr.length;
const stdDeviation = Math.sqrt(arr.reduce((sum, value) => sum + Math.pow(value - mean, 2), 0) / arr.length);
return arr.map(value => (value - mean) / stdDeviation);
}
function scoreSentence(text) {
const sentences = sbd.sentences(text);