Skip to content

Instantly share code, notes, and snippets.

View juliarose's full-sized avatar

Julia juliarose

  • United States
View GitHub Profile
@juliarose
juliarose / iterators.js
Last active February 6, 2024 14:55
hello world in JavaScript
const Filtered = Symbol('Filtered');
const Break = Symbol('Break');
class CharIterator {
constructor(string) {
this.string = string;
this.index = 0;
}
use std::str::FromStr;
use std::marker::PhantomData;
use serde::de::{self, Visitor};
pub struct StringOrU32Visitor<T> {
marker: PhantomData<T>,
}
impl<T> StringOrU32Visitor<T> {
pub fn new() -> Self {
@juliarose
juliarose / postgres.commands.psql
Last active March 27, 2024 17:00
Postgres commands
# Connect remotely from command line
psql -h <REMOTE HOST> -p 5432 -U <DB_USER> <DB_NAME>
# USE database;
\c databasename;
# SHOW TABLES;
\dt;
# SHOW COLUMNS FROM tablename
@juliarose
juliarose / deletelogs.sh
Created March 10, 2023 12:28
Deletes all files matching ".log" in current directory
#!/bin/sh
find . -type f -name "*.log*" -delete
@juliarose
juliarose / standard-deviation.js
Created March 5, 2023 02:35
Calculates standard deviation
/**
* Gets the standard deviation from a set of numbers.
* @example
* const { mean, stdv } = getStandardDeviation([10, 10, 10, 10, 5]);
* console.log(mean); // 9
* console.log(stdv); // 2
* @param {[number]} numbers - An array of numbers.
* @returns Object containing `mean` and `stdv`.
*/
function getStandardDeviation(numbers) {
fn main() {
let mut s = String::with_capacity(100);
s.push_str("coffee and 🍌");
s.shrink_to_fit();
println!("`{s}` {} {}", s.len(), s.capacity());
for c in '0'..='🍌' {
if c.is_control() {
type Color = [u8; 3];
/// Blends two colors.
fn blend_colors(a: Color, b: Color, amount: f32) -> String {
a.into_iter().zip(b)
.map(|(a, b)| {
let a = a as f32 * (1.0 - amount);
let b = b as f32 * amount;
let sum = (a + b) as u8;
@juliarose
juliarose / round_to_nearest_divisor.rs
Created February 27, 2023 03:39
Rounds number to the nearest divisor.
use num_traits::cast::AsPrimitive;
/// Rounds number to the nearest divisor.
pub fn round_to_nearest_divisor<T>(num: T, divisor: T) -> T
where
T: AsPrimitive<f32>,
f32: AsPrimitive<T>,
{
let divisor: f32 = divisor.as_();
let num: f32 = num.as_();
@juliarose
juliarose / files.rs
Last active February 13, 2023 18:33
Read/write files in Rust
// https://stackoverflow.com/a/31193386
use std::fs;
use std::io;
fn main() -> Result<(), io::Error> {
// Read a file to a String
let data = fs::read_to_string("/etc/hosts")?;
println!("{}", data);
// Read a file as a Vec<u8>
const getPixels = require("get-pixels");
const fs = require('fs');
const { promisify } = require('util');
const readFile = promisify(fs.readFile);
const path = require('path');
async function getPixelsForImage(imagePath) {
return new Promise((resolve, reject) => {
getPixels(imagePath, (error, pixels) => {
if (error) {