jono's recent activity
-
Comment on What's a simple, cheap way to run a database-backed website as a hobbyist? in ~comp
-
Comment on Do you have any unnoticed/underrated youtube channel suggestions? in ~misc
jono (edited )LinkMostly gaming related with some other content: Razbuten is one of those channels that I have no idea how I stumbled upon. Production quality is fantastic and his writing is just superb, really...Mostly gaming related with some other content:
Razbuten is one of those channels that I have no idea how I stumbled upon. Production quality is fantastic and his writing is just superb, really interesting insights on video games and other topics.
DimeTree I found due to his "The Elder Scrolls Problem" series and while I don't necessarily agree with everything he says, he's got some decent funny commentary.
Gamechamp3000 is just a lot of fun, both his VG myths and Dumb Fun Gaming series are great.
-
Comment on Programming Challenge: Markov Chain Text Generator in ~comp
jono Fantastic! I honestly cannot stop laughing at that image. Well done! I was thinking of doing a dict of dicts too but wasn't sure if that would be any better than just a dict of lists like I have...Fantastic! I honestly cannot stop laughing at that image. Well done! I was thinking of doing a dict of dicts too but wasn't sure if that would be any better than just a dict of lists like I have done, plus requires the extra effort working out probability.
-
Comment on Programming Challenge: Markov Chain Text Generator in ~comp
jono (edited )LinkRust Probably not the best implementation, but definitely feel like I'm starting to get the hang of this language. Still get confused whenever errors to do with lifetimes pop up. Haven't...Rust
Probably not the best implementation, but definitely feel like I'm starting to get the hang of this language. Still get confused whenever errors to do with lifetimes pop up. Haven't implemented saving or loading a Markov Chain directly. I ran a different, messier version with two words as the state on 700MB of AskReddit comments and got a couple of funny generations, didn't save them but might generate some more later.
extern crate rand; use rand::prelude::{Rng, thread_rng}; use std::collections::HashMap; use std::error::Error; use std::fs::File; use std::io::prelude::Read; use std::process; fn main() { let seed = "be".to_string(); let map = match load_map("map.txt") { Ok(map) => map, Err(_) => gen_map_from("source.txt").unwrap_or_else(|err| { println!("Error: {}", err); process::exit(1); }), }; println!("{}", gen_string_from(map, seed)); } fn load_map(filename: &str) -> Result<HashMap<String, Vec<String>>, Box<Error>> { let mut f = File::open(filename)?; let mut contents = String::new(); f.read_to_string(&mut contents)?; unimplemented!() } fn gen_map_from(filename: &str) -> Result<HashMap<String, Vec<String>>, Box<Error>> { let mut map: HashMap<String, Vec<String>> = HashMap::new(); let mut contents = String::new(); let mut f = File::open(filename)?; f.read_to_string(&mut contents)?; let contents = contents .to_lowercase() .replace(".", " .") .replace(";", " ;"); for (first, second) in contents .clone() .split_whitespace() .zip(contents.split_whitespace().skip(1)) { map.entry(first.to_string()) .or_insert(Vec::new()) .push(second.to_string()); } Ok(map) } fn gen_string_from(map: HashMap<String, Vec<String>>, mut word: String) -> String { let mut vec: Vec<String> = Vec::new(); while word != ".".to_string() { vec.push(word.to_string()); let word_vec = map.get(&word).unwrap(); word.clear(); word.push_str(thread_rng().choose(word_vec).unwrap()); } vec.push(word); vec.join(" ").replace(" .", ".").replace(" ;", ";") }
-
Programming Challenge: Markov Chain Text Generator
Markov Chains are a stochastic model describing a sequence of possible events in which the probability of each event depends only on the state attained in the previous event. By analyzing a...
Markov Chains are a stochastic model describing a sequence of possible events in which the probability of each event depends only on the state attained in the previous event. By analyzing a document in some way and producing a model it’s possible to use this model to generate sentences.
For example, let’s consider this quote:
Be who you are and say what you feel, because those who mind don't matter, and those who matter don't mind.
Let’s start with a seed of
be
, which there is only one of in this text and it’s following word iswho
. Thus, a 100% chance of the next state beingwho
. Fromwho
, there are several next states:you
,mind
, andmatter
. Since there are 3 options to choose from, the next state has a 1/3 probability of each. It’s important that if there were for example two instances ofwho you
thenyou
would have a 2/4 probability of next state. Generate a random number and choose the next state, perhapsmind
and continue until reaching a full stop. The string of states we reached is then printed and we have a complete sentence (albeit almost certainly gibberish).Note: if we were in the state
mind
, our next two options would be.
ordon’t
, in which if we hit.
we would end the generation. (or not, up to you how you handle this!)To take it a step further, you could also consider choosing the number of words to consider a state. For example, two words instead of one:
those who
has two possible next states:who matter
orwho mind
. By using much longer strings of words for our states we can get more natural text but will need much more volume to get unique sentences.This programming challenge is for you to create a Markov Chain and Text Generator in your language of choice. The input being a source document of anything you like (fun things include your favourite book, a famous person’s tweets, datasets of reddit / tildes comments), and possibly a seed. The output being a sentence generated using the Markov Chain.
Bonus points for:
- Try it a bunch of times on different sources and tell us the best generated sentences
- Using longer strings of words for the state, or even having it be variable based on input
- Not requiring a seed as an input, instead implementing that into your Markov Chain (careful as infinite loops can occur without considering the seed)
- Implement saving the Markov Chain itself, as it can take very long to generate with huge documents
- Particularly Fast, efficient, short or unique methods
Good luck!
P.S A great place to find many large plain text documents for you to play with is Project Gutenberg.
17 votes -
Comment on Programming Challenge: Anagram checking. in ~comp
jono I decided to modify it to work with more than two strings, the function requiring a vector of strings instead. It is however slightly slower for two strings. fn main() { let s_vec = vec![...I decided to modify it to work with more than two strings, the function requiring a vector of strings instead. It is however slightly slower for two strings.
fn main() { let s_vec = vec![ "anagram".to_string(), "nag a ram".to_string(), "mana rag".to_string(), ]; assert!(anagram(s_vec)); } fn anagram(s_vec: Vec<String>) -> bool { let mut sorted_s_vec: Vec<Vec<u8>> = Vec::new(); for mut s in s_vec { s.retain(|c| c.is_alphabetic()); let mut sorted_s = s.to_lowercase().into_bytes(); sorted_s.sort_unstable(); sorted_s_vec.push(sorted_s) } sorted_s_vec.dedup(); sorted_s_vec.len() == 1 || sorted_s_vec.len() == 0 }
-
Comment on Programming Challenge: Anagram checking. in ~comp
jono Change !c.is_whitespace() to c.is_alphabetic() for any alphabetic character, or otherwise c.is_digit(36) for any 0-9 A-z.Change !c.is_whitespace() to c.is_alphabetic() for any alphabetic character, or otherwise c.is_digit(36) for any 0-9 A-z.
-
Comment on Programming Challenge: Anagram checking. in ~comp
jono (edited )LinkRust I've only just started learning Rust and have only coded as a hobby. How'd I do? fn main() { let s1 = "anagram".to_string(); let s2 = "nag a ram".to_string(); assert!(anagram(s1, s2)); //...Rust
I've only just started learning Rust and have only coded as a hobby. How'd I do?
fn main() { let s1 = "anagram".to_string(); let s2 = "nag a ram".to_string(); assert!(anagram(s1, s2)); // True } fn anagram(s1: String, s2: String) -> bool { let sorted_s1 = sort_string(s1); let sorted_s2 = sort_string(s2); sorted_s1 == sorted_s2 } fn sort_string(mut s: String) -> Vec<u8> { s.retain(|c| !c.is_whitespace()); let mut sorted_s = s.to_lowercase().into_bytes(); sorted_s.sort_unstable(); sorted_s }
Edit:
cargo bench
puts it at 572 ns/iter (+/- 11) to run the function anagram():mod tests { use super::*; use test::Bencher; #[bench] fn count_letters_bench(b: &mut Bencher) { b.iter(|| anagram("nag a ram".to_string(), "anagram".to_string())) } }
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono keyhero is probably my favourite. 10fastfingers is quick and dirty and a bit of an ego boost as the words are so easy. keybr is well liked for ironing out any problem areas you might have...keyhero is probably my favourite. 10fastfingers is quick and dirty and a bit of an ego boost as the words are so easy. keybr is well liked for ironing out any problem areas you might have (particularly inconsistent speed with certain letters).
The graph looks like an excel graph, so he probably recorded his WPM in excel.
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono Good luck developing your own! I've been learning how to code over the last year and writing a program that generates an optimized layout based on a set of user inputted values has been a good...Good luck developing your own! I've been learning how to code over the last year and writing a program that generates an optimized layout based on a set of user inputted values has been a good learning experience for me. I tried in Python a long time ago and might try again in Rust now that I'm learning it.
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono Fantastic, good luck with your switch! Despite it being hell I actually thoroughly enjoyed those first few weeks.Fantastic, good luck with your switch! Despite it being hell I actually thoroughly enjoyed those first few weeks.
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono Many of the most common keyboard layouts don't effect punctuation beyond ;,./ however there are some layouts that try to optimize many common programming symbols such as []{}() etc. Programmers...Many of the most common keyboard layouts don't effect punctuation beyond ;,./ however there are some layouts that try to optimize many common programming symbols such as []{}() etc. Programmers Dvorak is one such example. MTGAP takes it steps further by putting letters like J on QWERTY +=.
Short answer is yes, it can be a pain. Long answer is even before I learned QWERTY I was an ESDF guy anyway, so I had to change 50% of the existing keybinds already. With Colemak, with each new game I go into the controls and change everything. Games that don't allow changing control bindings I just press two buttons on my keyboard and it switches back and forth between QWERTY and Colemak instantly.
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono QWERTY I generally typed at around 100 wpm. I reached 90 wpm on Colemak in 3 weeks at which point I stopped directly practicing daily. I now type at about 110-120, 130 on a good day.QWERTY I generally typed at around 100 wpm. I reached 90 wpm on Colemak in 3 weeks at which point I stopped directly practicing daily. I now type at about 110-120, 130 on a good day.
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono Awesome! As I have gotten deeper and deeper into knowing about different layouts, I definitely think Carpalx is a great layout for those that agree with the heuristics chosen to generate it. Steno...Awesome! As I have gotten deeper and deeper into knowing about different layouts, I definitely think Carpalx is a great layout for those that agree with the heuristics chosen to generate it. Steno is also mindbogglingly cool, though I at least admit to myself it's probably not worth the effort to learn as the benefits it provides won't exactly come in super handy with my use case of my computer. Good luck learning steno!
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono My one piece of advice before you go deep into Dvorak: consider browsing other layouts to see if you agree more with the ideals of other layout creators. I believe if you're gonna make the change,...My one piece of advice before you go deep into Dvorak: consider browsing other layouts to see if you agree more with the ideals of other layout creators. I believe if you're gonna make the change, you might as well go all out. Dvorak is generally considered very dated by most layout enthusiasts. It does have one very strong advantage: ubiquity. You can be confident if you have to use someone else's computer, you'll be able to change layouts within an at least reasonable time. If that is important to you then I absolutely would suggest Dvorak.
Otherwise, some examples to start off your research include Carpalx, Colemak, MTGAP, Workman and Norman.
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono I program now and then and use a second layer on my keyboard to put these symbols on my home row. Makes it very easy to reach and is even more ergonomic. Not for everyone as some people can't wrap...I program now and then and use a second layer on my keyboard to put these symbols on my home row. Makes it very easy to reach and is even more ergonomic. Not for everyone as some people can't wrap their heads around switching layers, but works brilliantly for me.
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono (edited )Link ParentAgreed, too many people get caught up in the mindset of switching for speed, or even argue against switching because it doesn't increase speed. I switched because I simply thought it was a more...Agreed, too many people get caught up in the mindset of switching for speed, or even argue against switching because it doesn't increase speed. I switched because I simply thought it was a more efficient layout, resulting in an ergonomic and thus enjoyable experience. The rolls of Colemak create a hard to describe experience that is genuinely pleasurable, like rolling your fingers on a desk.
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono I absolutely love the Kinesis and plan to make a Dactyl one day which implements many of the features of the Kinesis. I currently use a keyboard that is similar in some regards, which pairs very... -
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono (edited )Link ParentSimply because I aligned more closely with the mindset of the Colemak creator. Dvorak makes many strange choices that made me veer far away, though I admit Dvorak was my first attempt at switching...Simply because I aligned more closely with the mindset of the Colemak creator. Dvorak makes many strange choices that made me veer far away, though I admit Dvorak was my first attempt at switching which allowed me to find Colemak. That being said, even Colemak made choices that I don't necessarily agree with and have chosen to change resulting in the slightly modified version I use today.
I use a completely programmable keyboard that I can program to my hearts content, and move between computers as I like.
Without a doubt I found typing on Colemak miles better than QWERTY, otherwise I would not have committed to making the switch. Typing QWERTY now feels very awkward and unwieldy, though I can when necessary. I never suffered any problems with QWERTY but just have the type of personality that absolutely loves efficiency and strive to optimize pretty much everything in my life, leading me to find alternate keyboard layouts!
-
Comment on Dvorak, Colemak and other alternative keyboard layouts in ~hobbies
jono Oh yeah, I'm quite certain it's partly due to me actually being interested in my layout and practicing it often. I did also change my actual physical keyboard layout during that time to a split...Oh yeah, I'm quite certain it's partly due to me actually being interested in my layout and practicing it often. I did also change my actual physical keyboard layout during that time to a split columnar-staggered layout similar to the ErgoDox. It also allows me to program each key myself, so if necessary I can use it at computers other than my own. However, switching via software is as easy as changing languages such as QWERTZ and AZERTY, though anything less common than Dvorak will need to be installed on Windows, and anything less common than Colemak on Linux and MacOS. Some people opt to instead make use of PKL.
DynamoDB On-Demand is practically free under 25GB (or you may be eligible for free tier) if you're fine with NoSQL.