Skip to content

Instantly share code, notes, and snippets.

@suyash
suyash / AnimatedSweepGradient.kt
Last active July 3, 2024 20:38
Animated Sweep Gradient in Compose
private fun sweepGradientShaderWithOffset(
vararg colorStops: Pair<Float, Color>,
offset: Float = 0f,
center: Offset = Offset.Unspecified
): Brush {
return object : ShaderBrush() {
override fun createShader(size: Size): Shader {
// https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/Brush.kt;l=576-583;drc=a18f72ab3de68971fb30d894d41f4441aa09fd4f
val normalizedCenter =
if (center.isUnspecified) {
@suyash
suyash / client.c
Created January 2, 2017 15:53
UDP echo client-server implementation
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
int main() {
const char* server_name = "localhost";
const int server_port = 8877;
@suyash
suyash / README.md
Last active June 10, 2024 17:31
mmap examples

identical mmap programs in C and go

@suyash
suyash / client.c
Created January 2, 2017 16:36
TCP echo client-server in C
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
int main() {
const char* server_name = "localhost";
const int server_port = 8877;
@suyash
suyash / Cargo.toml
Last active December 27, 2022 14:51
@karpathy's min-char-rnn.py in rust
[package]
name = "min-char-rnn-rs"
version = "0.1.0"
authors = ["Suyash <suyash93@protonmail.com>"]
edition = "2018"
[dependencies]
rulinalg = "0.4.2"
rand = "0.6.4"
indicatif = "0.11.0"
@suyash
suyash / kmp.rs
Created July 8, 2020 13:26
Knuth-Morris-Pratt implementation
//! Knuth-Morris-Pratt implementation
//!
//! See Chapter 17 in Blandy + Orendorff
/// computes the KMP longest prefix-suffix function
pub fn kmp<T: AsRef<[u8]>>(pattern: T) -> Vec<usize> {
let pattern = pattern.as_ref();
let n = pattern.len();
let mut ans = vec![0; n + 1];
@suyash
suyash / segment_tree.rs
Created July 8, 2020 07:49
Generic Segment Tree implemented for custom comparator and min functions.
//! Generic Segment Tree implemented for custom comparator and min functions.
//!
//! See Chapters 15, 16 in Blandy and Orendorff
/// Segment Tree allows for querying information over ranges in a continuous data stream.
pub struct SegmentTree<T, Comparator, Minimum> {
tree: Vec<T>,
n: usize,
f: Comparator,
d: Minimum,
@suyash
suyash / jfsStore.js
Last active May 12, 2020 07:21
MemoryStore + JFSStore
import { Store } from 'express-session';
import JFS from 'jfs';
export default class JFSStore extends Store {
constructor(location) {
super();
this.db = new JFS(location || 'data');
}
@suyash
suyash / mixture_density_nets_2d.ipynb
Last active October 6, 2019 04:56
Mixture Density Nets 2D
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@suyash
suyash / canny_edge_detector.ipynb
Created September 27, 2019 05:50
Canny Edge Detector
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.