Skip to content

Instantly share code, notes, and snippets.

View pmkroeker's full-sized avatar

Peter pmkroeker

View GitHub Profile
use std::convert::TryInto;
use chrono::prelude::*; // 0.4.11
pub struct Mondays {}
impl Mondays {
pub fn count(birth: chrono::NaiveDate, curr_date: chrono::NaiveDate) -> i64 {
// start work at age 22
let start_work = birth + chrono::Duration::days(22 * 365);
// retire at age 78
// https://dev.to/thepracticaldev/daily-challenge-29-xs-and-os-12mj
pub fn xo (value: &str) -> bool {
let value = value.to_lowercase();
let count_x = value.matches("x").count();
let count_o = value.matches("o").count();
count_x == count_o
}
#[cfg(test)]
pub fn ccbreaker (value: &str) -> String {
value.chars()
.into_iter()
.map(|c| if c.is_uppercase() { format!(" {}", c.to_lowercase()) } else { c.to_string() })
.collect::<String>()
}
#[cfg(test)]
mod tests {
use super::*;
// Convert number to hex string.
pub fn to_hex (value: i32) -> String {
let value = if value > 255 { 255 } else if value < 0 { 0 } else { value };
format!("{:02X}", value)
}
// Join all hex strings together from rgb input.
pub fn rgb (r: i32, g: i32, b: i32) -> String {
format!("{}{}{}", to_hex(r), to_hex(g), to_hex(b))
}
@pmkroeker
pmkroeker / leastsquares.js
Last active May 20, 2018 01:33
Creates linear regression data for use in d3.js
//Original least squares found here: http://bl.ocks.org/easadler/edae96ae440aa0361a4d#leastsquares.js
//from Adam Sadler!!
//r squared calculation was added by me.
function LeastSquares(values_x, values_y) {
var sum_x = 0;
var sum_y = 0;
var sum_xy = 0;
var sum_xx = 0;
var count = 0;