Author Topic: Programming Megathread  (Read 104179 times)

Casting a positive float to an int is the fastest way to floor it.

do any of you guys use programmr.com as a learning site also?

ill just ask again

I love seeing the silly things people do in code

I remember seeing in our code base at work a (0).ToString() instead of just a "0"

Casting a positive float to an int is the fastest way to floor it.
True, and I'm used to C-style casts since that's what I started with, but I think in my C# experience, other people prefer when you're a bit more explicit about how scenarios like this should work, so using .Floor() or .Ceil() tells you exactly what's going to happen.

If any of you are crypto nerds and are interested in Keybase, send me a PM because I have 7 alpha invites.

tl;dr: It's a social-ish network that lets you connect your pgp key to social media accounts.
« Last Edit: September 14, 2016, 07:15:37 PM by Pecon »

My natural language processing class has been really interesting so far.  I was worried about how hard the class will be since it was a grad student course and the professor has a really thick Chinese accent but he's using some solid slides and answers one on one questions pretty well.  So far the hardest part has been getting used to python which I don't think I've done anything real in ever.

If any of you are crypto nerds and are interested in Keybase, send me a PM because I have 7 alpha invites.

tl;dr: It's a social-ish network that lets you connect your pgp key to social media accounts.

I had a crypto class and enjoyed but it was a really brief glance of the field but it's all really interesting to me.  So does that site just basically let you have a public key that's easy for everyone to find so stuff is easily verified?

I had a crypto class and enjoyed but it was a really brief glance of the field but it's all really interesting to me.  So does that site just basically let you have a public key that's easy for everyone to find so stuff is easily verified?
Kinda. Take my page as an example: https://keybase.io/pecon
It links to and verifies cryptographic proofs on all the profiles you link to it, on top of having your public key.

So far the hardest part has been getting used to python which I don't think I've done anything real in ever.
I'm a python freak
also a javascript freak
I love them both. sometimes I use one or another. I don't know what determines whether I choose to use one or the other for a given task, aside from perhaps library availability

at work I have this stupid, awful task that involves me making up random numbers off the top of my head within a certain range
I got tired of making them up myself (previously my least favorite part of doing it), so I made a python script to do it for me

import random

parts = [
    ["86697-C2000", 302.0, 15, 3],
    ["86697-C2200", 292.0, 6,  3],
    ["86697-C2300", 288.0, 15, 3],
    ["84716-4Z000", 180.0, 15, 5],
    ["86717-4Z000", 185.0, 15, 5],
    ["55163-F2000", 705.6, 15, 3]
]

output = ""

for part, avg, rng, samples in parts:
    output += part + ": "
    sample_list = []
    for i in range(samples):
        sample_list.append('{:.1f}'.format(random.uniform(avg - rng, avg + rng)))
    output += ', '.join(sample_list) + '\n'

print(output)


output generally looks something like this:

86697-C2000: 287.9, 295.0, 309.5
86697-C2200: 293.6, 286.2, 286.2
86697-C2300: 293.2, 302.4, 283.9
84716-4Z000: 182.1, 171.4, 183.6, 194.3, 176.1
86717-4Z000: 184.3, 190.8, 190.6, 174.8, 199.3
55163-F2000: 700.8, 710.0, 693.8


in this particular case it's easy to explain that I chose python because its random module is much more convenient than javascript's Math.random()
but sometimes the reasons are much more abstract

so i'm taking a programming class in school (they only do java so uh hey)

i just installed the eclipse IDE but my school uses jcreator so i'm a bit confused with all this fluff in eclipse

so i'm taking a programming class in school (they only do java so uh hey)

i just installed the eclipse IDE but my school uses jcreator so i'm a bit confused with all this fluff in eclipse
Eclipse is one of the most popular IDEs around, with a stuffload of downloadable plugins. Its written mostly in Java

i'm aware but like. whoa. what are all these features. i'm used to this (minus the sidebars with only one panel):

while eclipse looks like this:

i tried to make it look as close to jcreator as i could but i can't get over all this fancy formatting

Eclipse is pretty complex, it requires time to understand it.

ignore everything you don't understand
if you know how to type and click that little run button, you're pretty much good to go

Python was definitely the best language for what I was trying to do.  It also seems like python is the best for dealing with text, from regex and formatting to multidimensional arrays or lists or whatever.

The program I had to make creates a matrix that's the height and width of two strings which is already annoying to do in C++.  Then passing a multidimensional array to functions in C++ another pain in the ass.  But with python it was crazy simple, the only thing I got hung up on was how the X and Y coordinates are backwards which was easy to get over.

Overall I like python but don't know if I'll use it for most of what I do.  The syntax is just odd but I'm sure that wouldn't be a problem after doing any amount of work in it.  I really wanna give R a shot since that language seems like it was made for doing all the stuff I hate to do in C++ and the fact you integrate with C++ is pretty cool.

Here's a link to the program so far

I don't remember* why I ended up deciding to learn to use python in the first place, but I was pretty reluctant to do so, because of its syntax
then I fell in love

I'm not sure what you mean by X and Y coordinates though. (2, 3) is still (2, 3). arrays aren't meant specifically to represent coordinate planes, so why would the first index select from the innermost array? that'd make using arrays in python (and in any other language, where it certainly doesn't work like that either) 1000000x more complicated
maybe you'd like numpy. it has a matrix data type that can be accessed with coordinates. I can't remember exactly what the API is like for numpy but it goes something like this:

import numpy
m = numpy.matrix([
  [['a'], ['b'], ['c']],
  [['i'], ['j'], ['k']],
  [['x'], ['y'], ['z']]
])
m[1, 1]  # == 'j', I think


*turns out I don't need to remember
« Last Edit: September 14, 2016, 10:10:49 PM by Foxscotch »