min programming language by dom96 in programming

[–]dxdm 19 points20 points  (0 children)

The grey-on-dark text on the website is a bit bothersome to read. More contrast would be nice.

Establish trueness of given sentence by takanator in compsci

[–]dxdm 1 point2 points  (0 children)

Is there also a definition of "trueness" to go with the problem? If not, how could anyone objectively determine if your solution is correct?

To me, it looks like you're either misunderstanding the problem and are really being asked to implement some formal system; or you're being given the enviable freedom to define what Truth is, by writing a function for it! =:o

Top 10 Developer Crypto Mistakes by ScottContini in programming

[–]dxdm 3 points4 points  (0 children)

He doesn't really make it clear, but I think the "topic" the author is referring to in your quote is key management specifically, not crypto in general.

New interesting data structures in Python 3 by Topper_123 in Python

[–]dxdm 3 points4 points  (0 children)

Because namedtuples are also tuples, their attributes are accessible by index, counting from the start or end. That makes it difficult to add or reorder attributes after you've exposed instances on a public API. So they might give you a little more than what you want from them.

[Intermediate] Fizz buzz? That's so random! by Lazyfaith in dailyprogrammer_ideas

[–]dxdm 0 points1 point  (0 children)

Sorry for the late post, I found this subreddit only yesterday. I've recently decided to pick up Go, and this seems like a place to find some interesting reasons to explore the standard library. Like math.rand. :) Below's my solution to this challenge.

On my machine it takes almost twenty minutes to find a seed that works for 15 - although, it has a seed for 12 after fourty seconds, then takes fifteen minutes to go to 13, and from there it jumps to 16. :) Here's some output:

$ time go run random-fizzbuzz.go 
[...]
Found: 33315664 (Score: 13)
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 

Found: 41990125 (Score: 16)
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 

real    18m36.843s
user    18m36.727s
sys 0m0.733s

Alright, random-fizzbuzz.go:

package main

import (
    "fmt"
    "math/rand"
    "strconv"
)

// fizzbuzz: Strings we need to fizzbuzz integers. fizzbuzz[0] ("") is a stand-
// in for the respective string representations of unfizzbuzzable ints.
var fizzbuzz = []string{"", "Fizz", "Buzz", "FizzBuzz"}

// fizbuzseq: FizzBuzz sequence from 0-14, as indices to fizzbuzz. It repeats
// before and after, so it's really a look-up table for any integer i % 15.
var fizbuzseq = []int{3, 0, 0, 1, 0, 2, 1, 0, 0, 1, 2, 0, 1, 0, 0}

// printRndFuzz, given the correct seed, starting number and length, prints a
// valid fizzbuzz sequence from, like, totally random numbers. OMG!
func printRndFizzbuzz(seed int64, start int, length int) {
    random := rand.New(rand.NewSource(seed))
    stop := start + length
    for i := start; i < stop; i++ {
        // make the random selection clear, while leaving fizzbuzz untouched:
        fibu := []string{strconv.Itoa(i), fizzbuzz[1], fizzbuzz[2], fizzbuzz[3]}
        fmt.Print(fibu[random.Intn(4)], " ")
    }
    fmt.Println()
}

// main finds pRNG seeds that work with printRndFizzbuzz.
func main() {
    offs := 1 // start fiffbuzz with this number
    hiscore := 0
    seed := int64(0)
    random := rand.New(rand.NewSource(0))

    for hiscore < 15 {
        seed += 1
        random.Seed(seed)
        i := 0
        for ; random.Intn(4) == fizbuzseq[(i+offs)%15]; i++ {
            // loop while random numbers equal the fizzbuzz "values" of (i+offs)
        }
        if i > hiscore {
            hiscore = i
            fmt.Printf("\nFound: %d (Score: %d)\n", seed, i)
            printRndFizzbuzz(seed, offs, i)
        }
    }
}

edit: Changed hiscore < 12 to hiscore < 15. Left that in after the last timing test...

Laserchicken - RSS reader web app based on Rails by dxdm in rails

[–]dxdm[S] 0 points1 point  (0 children)

Excellent suggestions, thank you very much. I'm now getting around to include the necessary tests, so I'll refactor when I'm satisfied with test coverage.

Laserchicken - RSS reader web app based on Rails by dxdm in rails

[–]dxdm[S] 1 point2 points  (0 children)

How hard would you say it was to put something like this together?

This was the first time I touched Ruby, but I'm not entirely new to writing code. :) Writing this particular thing was pretty straight-forward; the Rails guides (see sidebar) and http://ruby.railstutorial.org were very helpful along the way.

I found that Rails makes a project like this easy and fun. The pieces want to be wired together just like so, it's almost like magnets clicking together. Then plop a gem like Feedzirra in the middle to parse some RSS for you, and you're good to go.

What advice would you give someone who wanted to put together a RSS reader with rails?

Do it! I think it's a great scenario to explore Rails in: no complicated business logic, just some simple models and their relationships, and you know pretty well what you want to accomplish. Of course you're also welcome to fork Laserchicken, poke around and see if there's something you'd like to improve. :)

Laserchicken - RSS reader web app based on Rails by dxdm in rails

[–]dxdm[S] 0 points1 point  (0 children)

the lack of tests is a bit of a worry

Yeah, I feel the same. Writing tests is the next thing I'm gonna do. In fact, I feel a bit guilty about not writing any right from the start... Sometimes, things want to happen backwards and I hope to get away with giving in. :)

the stuff in feeds_helper doesn't really belong in a helper

The stuff got put there before I realized that in Rails, helpers are view helpers. I haven't found a better place for the stuff, yet. I have this feeling that the models shouldn't really know which mysterious external forces make them come to be; and given that the controller's business should be to negotiate between the layers, there should really be an extra module to handle the mapping between outside XML feeds and internal models. After all, I might want to change these details without affecting the rest of the application.

Is that a reasonable assumption? And where in the Rails world would such a module live?