Skip to content

Instantly share code, notes, and snippets.

View kracekumar's full-sized avatar

Kracekumar kracekumar

View GitHub Profile
@kracekumar
kracekumar / odd_sum.gleam
Created May 27, 2025 23:46
Given two arrays, return all pairs (where each number is in each array) whose sum is an odd number.
import gleam/list
import gleam/result
pub fn oddsum(arr1, arr2) {
list.map(arr1, fn(a) {
list.map(arr2, fn(b) { [a, b]})}) |> list.flatten |> list.map(fn(x){
case {{result.unwrap(list.first(x), 0) + result.unwrap(list.last(x), 0)} % 2} {
1 -> x
_ -> []
}
@kracekumar
kracekumar / longest_common_prefix.gleam
Last active May 5, 2025 21:51
Write a function that takes a list of strings and returns the longest string that is a prefix of at least two strings in the list. longestCommonPrefix(["flower","flow","flight"]) -> "fl" longestCommonPrefix(["dog","racecar","car"]) -> "" longestCommonPrefix(["interstellar","internet","internal","interval"]) -> "inte"
import gleam/int
import gleam/io
import gleam/list
import gleam/string
pub fn chars_at_position(pos: Int, as_char: List(List(String))) {
// given a position, create a list of characters
list.map(as_char, fn(x) {
case { list.last(list.take(x, pos)) } {
Ok(val) -> val
@kracekumar
kracekumar / compress.py
Created April 28, 2025 09:50
Given an array of characters chars, compress it such that consecutive duplicate characters are replaced with the character followed by the count of duplicates. If the count is 1, omit it.
from itertools import groupby
def compress(items):
if not items:
return []
result = []
for item, group in groupby(items):
group_length = sum(1 for _ in group)
result.append(item)
@kracekumar
kracekumar / calculate_ingredients.py
Last active April 22, 2025 13:46
Given an array of objects representing ingredients (each with a name and amount per serving), and a target number of servings, write a function to calculate the required amount of each ingredient for the target servings. Return the results as an array of objects with name and amount. Can you do this in less than 5 lines? In one?
"""
Given an array of objects representing ingredients (each with a name and amount per serving), and a target number of servings, write a function to calculate the required amount of each ingredient for the target servings. Return the results as an array of objects with name and amount. Can you do this in less than 5 lines? In one?
Example:
const ingredients = [
{ name: "flour", amount: 200 }, // 200g per
{ name: "sugar", amount: 100 }, // 100g per
{ name: "eggs", amount: 2 } // 2 eggs per
];
const targetServings = 3;
NATO_DICTIONARY = {
"A": "Alpha",
"B": "Bravo",
"C": "Charlie",
"D": "Delta",
"E": "Echo",
"F": "Foxtrot",
"G": "Golf",
"H": "Hotel",
"I": "India",
@kracekumar
kracekumar / episode1.srt
Created January 12, 2025 17:24
Subtitles generated by whisper for normal people episode 1 tv series. Command: uv run whisper /Users/kracekumar/Movies/TV/Normal.People.S01/audio/Normal.People.S01E01.aac --model turbo -f srt --output_dir /Users/kracekumar/Movies/TV/Normal.People/generated_subs/
1
00:00:00,000 --> 00:00:24,000
It's a simple game. You have 15 players. Give one of them the ball. Get it into the net.
2
00:00:24,000 --> 00:00:26,000
Very simple. Isn't it?
3
00:00:26,000 --> 00:00:31,000
"""
Datastructures
1. Tuple
2. List
3. Set
4. Dictionary
5. Class
"""
import datetime
Rust is a multi-paradigm, general-purpose programming language designed for performance and safety,
especially safe concurrency.
Rust is syntactically similar to C++, but can guarantee memory safety by using a borrow checker to validate references.
Rust achieves memory safety without garbage collection, and reference counting is optional.
Rust has been called a systems programming language and in addition to high-level features
such as functional programming it also offers mechanisms for low-level memory management.
First appearing in 2010, Rust was designed by Graydon Hoare at Mozilla Research, with contributions from
Dave Herman, Brendan Eich, and others.
The designers refined the language while writing the Servo experimental browser engine
@kracekumar
kracekumar / python.txt
Created February 6, 2022 18:04
Python Language
Python is an interpreted high-level general-purpose programming language.
Its design philosophy emphasizes code readability with its use of significant indentation.
Its language constructs as well as its object-oriented approach aim to help programmers write clear,
logical code for small and large-scale projects.
Python is dynamically-typed and garbage-collected.
It supports multiple programming paradigms, including structured (particularly, procedural),
object-oriented and functional programming. It is often described as a "batteries included" language
due to its comprehensive standard library.
@kracekumar
kracekumar / pyproject.toml
Created June 13, 2021 17:00
poetry unable to load sqlalchemy stubs
[tool.poetry]
name = "flask-sqlalchemy"
version = "0.0.1"
description = ""
authors = ["kracekumar <>"]
license = "MIT"
readme = ""
repository = ""
[tool.poetry.dependencies]