This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function fromCSV({ ctx }) => { | |
const { filePaths } = await dialog.showOpenDialog({ | |
filters: [{ name: "Comma seperated values", extensions: ["csv"] }], | |
}); | |
const csv = fs.readFileSync(filePaths[0], { encoding: "utf-8" }); | |
const lines = csv.split("\n"); | |
const keys = lines.shift()?.split(","); | |
for (const line of lines) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button className="flex content-center items-center justify-center rounded-full border-2 border-transparent bg-sky-800 py-2 px-3 text-base leading-normal text-sky-100 outline-none hover:bg-opacity-80 focus:ring-1 focus:ring-offset-2 active:ring-0 active:ring-offset-0 disabled:cursor-not-allowed disabled:bg-opacity-50"> | |
<span className="mx-1">Alle</span> | |
<span className="relative inline-flex"> | |
<span className="mr-1 flex rounded-full bg-sky-500 px-2 py-1 text-xs font-bold uppercase"> | |
{filtercount} | |
</span> | |
<span | |
className="absolute inline-flex h-full w-full animate-ping rounded-full bg-sky-400 opacity-75" | |
style={{ | |
animationIterationCount: 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<button id="choose-file">choose a file to write to</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::convert::TryFrom; | |
fn main() { | |
let names = vec!["Daniel", "Max", "Lewis"]; | |
let [daniel, max, lewis] = <[&str; 3]>::try_from(names).ok().unwrap(); | |
dbg!(daniel, max, lewis); | |
// daniel = "Daniel" | |
// max = "Max" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
pub enum Bucket { | |
One, | |
Two, | |
} | |
impl Bucket { | |
fn other(&self) -> Self { | |
match self { | |
Bucket::One => Bucket::Two, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let permutations = (0u8..10u8).permutations(letters.len()); | |
<!-- 105s --> | |
let possible_dicts: Vec<BTreeMap<char, u8>> = permutations | |
.filter_map(|permutation| { | |
let dict: BTreeMap<char, u8> = letters.iter().copied().zip(permutation).collect(); | |
if dict.iter().any(|(c, &n)| leading.contains(c) && n == 0) { | |
None | |
} else { | |
Some(dict) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
const VALID: [char; 4] = ['A', 'C', 'G', 'T']; | |
pub fn count(nucleotide: char, dna: &str) -> Result<usize, char> { | |
if !VALID.contains(&nucleotide) { | |
return Err(nucleotide); | |
} | |
match dna.chars().find(|c| !VALID.contains(c)) { | |
Some(c) => Err(c), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::{HashMap, HashSet}; | |
fn count_occurrences(message: &str) -> HashMap<char, usize> { | |
let unique: HashSet<char> = message.chars().collect(); | |
unique | |
.iter() | |
.map(|&c| (c, message.matches(c).count())) | |
.collect() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Determines whether the supplied string is a valid ISBN number | |
pub fn is_valid_isbn(isbn: &str) -> bool { | |
let numbers: Vec<u32> = isbn | |
.chars() | |
.filter_map(|c| match c { | |
'X' if Some('X') == isbn.chars().last() => Some(10), | |
_ => c.to_digit(10), | |
}) | |
.collect(); | |
if numbers.len() != 10 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn is_armstrong_number(num: u32) -> bool { | |
let digits: Vec<_> = num | |
.to_string() | |
.chars() | |
.filter_map(|n| n.to_digit(10)) | |
.collect(); | |
let num_digits = digits.len() as u32; | |
num == digits.iter().map(|n| n.pow(num_digits)).sum() | |
} |
NewerOlder