Skip to content

Instantly share code, notes, and snippets.

@paholg
paholg / main.rs
Created March 20, 2023 23:52
asdfler
use std::collections::HashSet;
use std::io::Write;
use std::path::Path;
use std::process::{Command, Output};
use std::str;
use std::vec::Vec;
use std::{fs, io};
use anyhow::{anyhow, bail};
use clap::Parser;
impl Solution {
pub fn search_range(nums: Vec<i32>, target: i32) -> Vec<i32> {
let (first, last) = find_first_last(&nums, target);
let first = first.map(|i| i as i32).unwrap_or(-1);
let last = last.map(|i| i as i32).unwrap_or(-1);
vec![first, last]
}
}
fn find_first_last(nums: &[i32], target: i32) -> (Option<usize>, Option<usize>) {
#!/usr/bin/env ruby
class FirstLast
attr_reader :data
def self.find(data, target)
new(data).find(target)
end
def initialize(data)
@paholg
paholg / aoc-2019-06.rb
Created December 6, 2019 11:47
Advent of Code 2019, Day 6 - Orbits, in Ruby
class Tree
attr_reader :head
def self.from_string(string)
tree = Tree.new(Node.new('COM'))
map = { 'COM' => tree.head }
string.split("\n").each do |line|
bodies = line.split(')')
orbitee = map[bodies[0]]
@paholg
paholg / aoc-2019-06.rs
Last active December 6, 2019 14:45
Advent of Code 2019 - Day 6, orbits
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
struct Tree<T> {
head: Rc<RefCell<Node<T>>>,
}
impl Tree<String> {
fn from_str(input: &str) -> Tree<String> {
@paholg
paholg / keybase.md
Created June 27, 2018 19:51
Keybase Proof

Keybase proof

I hereby claim:

  • I am paholg on github.
  • I am paho (https://keybase.io/paho) on keybase.
  • I have a public key ASAr75NheLefKgANlGk7RS-daJj6cN7lfhgMc1ke6AiE3Ao

To claim this, I am signing this object:

@paholg
paholg / files.py
Created June 27, 2018 01:40
Get files with the largest date in subdirectory name
#!/usr/bin/env python3
import glob
# This path should be to the directory outside the ones we want to glob over.
base_path = "path/to/outer/folder/"
# Set `filename` here to whatever the file is that's contained in all these directories.
filename = "file"
extern crate typenum;
use std::marker::PhantomData;
#[derive(Clone, Copy, Debug)]
struct Ranged<Min, Max> {
val: i64,
_marker: PhantomData<(Min, Max)>,
}
use std::marker::PhantomData;
extern crate typenum;
use typenum::consts as tnc;
use typenum::int::Integer;
use std::ops::{Add,Sub};
#![feature(const_fn)]
extern crate dimensioned;
extern crate float_cmp;
use dimensioned::{Dim, Dimension, Zero, P1, N1};
use dimensioned::si::{SI, m};
use float_cmp::{ApproxEq, Ulps};
type MeterPerSecond = SI<P1, Zero, N1>;