Skip to content

Instantly share code, notes, and snippets.

def train(df: pd.DataFrame, ycol: str, event_id: str) -> tuple[CatBoostClassifier, TrainTestTargetDistribution]:
df = get_quantile_binned_target(df, ycol)
# oversample the minority class by simple duplication
# we do this for stratified train test split strategy
df = df.append(df[df.groupby(ycol)[ycol].transform("count") == 1])
X: pd.DataFrame = df.drop(columns=[ycol])
y: pd.Series = df[ycol]
# boosters like catboost and xgboost need categorical variables to be encoded
# catboost can do this automatically
@jargnar
jargnar / news_sim.dart
Last active March 13, 2021 12:02
Android/Flutter simple news feed sim
import 'dart:typed_data';
import 'package:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:intl/intl.dart';
class ArticleModel {
String title;
String body;
// MIT
// Suhas Guruprasad, jargnar@gmail.com
const puppeteer = require("puppeteer");
const fetch = require("node-fetch");
const imagemin = require("imagemin");
const imageminMozjpeg = require("imagemin-mozjpeg");
const fs = require("fs").promises;
@jargnar
jargnar / edit_distance.rs
Created January 26, 2021 14:56
The minimum edit distance between two strings in Rust, LeetCode #72: https://leetcode.com/problems/edit-distance/
use std::collections::HashMap;
use std::cmp::min;
impl Solution {
pub fn min_distance(word1: String, word2: String) -> i32 {
let mut D: HashMap<(i32, i32), i32> = HashMap::new();
let m = word1.len() as i32;
let n = word2.len() as i32;
let w1: Vec<char> = word1.chars().collect();
@jargnar
jargnar / climbing_stairs.rs
Created January 26, 2021 08:02
Climbing Stairs
use std::collections::HashMap;
impl Solution {
pub fn fib(n: i32, cache: &mut HashMap<i32, i32>) -> i32 {
if n <= 2 { return n; }
else if !cache.contains_key(&(n-1)) && !cache.contains_key(&(n-2)) {
let a = Self::fib(n - 1, cache);
let b = Self::fib(n - 2, cache);
cache.insert(n - 1, a);
@jargnar
jargnar / 0062_unique_paths_stupid_solution.py
Created March 21, 2020 15:48
0062_unique_paths_stupid_solution.py
"""
The naive/stupid version where I actually created a tree... for unique paths...
<https://leetcode.com/problems/unique-paths>
before I realised we could just do simple DP of: #paths(i, j) = #paths(i, j + 1) + #paths(i + 1, j)
ouch.
"""
s0, r0, g0, p0, n0 = :C3, :D3, :E3, :G3, :B3
s, r, g, p, n = :C4, :D4, :E4, :G4, :B4
s2, r2, g2, p2, n2 = :C5, :D5, :E5, :G5, :B5
define :maya do
sleep 3
play_pattern_timed [s, s, r, s, r, s, r, r], 0.75, release: 3
sleep 3
play_pattern_timed [s, r, g, s, r, s, r, r], 0.75, release: 3
@jargnar
jargnar / duplicated_accumulator.go
Last active December 9, 2018 14:09
Find duplicated accumulator from a stream
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"github.com/AndreasBriese/bbloom"
)
@jargnar
jargnar / mysqrt.rkt
Last active October 7, 2018 08:39
Square-rooting in Racket
#lang racket
(define (mysqrt x)
;; a procedure to calculate square root of a number
;; starts with a guess and improves it until it is good enough
;; a guess can be improved by averaging itself with x/guess
(define (avg a b) (/ (+ a b) 2.0))
(define (improve-guess guess x) (avg guess (/ x guess)))
@jargnar
jargnar / restoreS3DeletedObjects.sh
Created July 28, 2018 08:57
Restore deleted S3 Objects by Prefix
bucket="SOME_BUCKET_NAME"
prefix="SOME_PREFIX"
objects="["
printf "\n\n>>> SALVAGING LOST DATA NOW\n\n"
while :
do
count=0