Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
gonadic io
Feb 16, 2011

>>=

prisoner of waffles posted:

More like the "very good programmers thread," amirite?

there are no good programmers though. literally the entire point of programmig is to take shortcuts and be as lazy as possible to get comptuers to do work for us. also computers are so complex there's absolutely no way to actually understand what's going on unless you're writing in the rawest of assembly/most trivial peripheral bit twiddling so we just throw code out there and hope it looks like it works.

i honestly love it.

Adbot
ADBOT LOVES YOU

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

fleshweasel posted:

put/post matters because one of them implies you should only change values for keys which are specified while the other implies that keys omitted from the most recent request should be removed from the entity. I don’t remember which is which

isn't the former PATCH and the second PUT?

my mental model was like this:

GET = select
PUT = upsert
DELETE = delete
PATCH = update
POST = generic "here's a command that should result in some (side) effects, let me know about them maybe"

redleader
Aug 18, 2005

Engage according to operational parameters
i tend to think of it as post = create, put = update, patch = partial update

redleader
Aug 18, 2005

Engage according to operational parameters
ok so serverless computing/functions-as-a-service: when and why would I actually want to use these? why are these cool + good and why/when would using these services be a better alternative to normal computering?

gonadic io
Feb 16, 2011

>>=
terrible programmer q: is there any advantage to making my local variables small int sizes/uints if i know they won't have any representation problems? i'm asking about rust specifically but i guess the question applies to any lang that has i8/u8/i16/u16.

i mean do they get aligned with wordsize anyway, so i might as well just use i/u size and call it a day? i'm getting pretty annoyed by the casting i need to do since all the library methods take usize/isize

cinci zoo sniper
Mar 15, 2013




redleader posted:

ok so serverless computing/functions-as-a-service: when and why would I actually want to use these? why are these cool + good and why/when would using these services be a better alternative to normal computering?

when your it is bad or when the service provided is too complex for cost/benefit to make sense. my last job used providers like that since our it could take a year to develop and deploy a solution that is a sub-kloc case:switch statement

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man

gonadic io posted:

terrible programmer q: is there any advantage to making my local variables small int sizes/uints if i know they won't have any representation problems? i'm asking about rust specifically but i guess the question applies to any lang that has i8/u8/i16/u16.

i mean do they get aligned with wordsize anyway, so i might as well just use i/u size and call it a day? i'm getting pretty annoyed by the casting i need to do since all the library methods take usize/isize

mostly that it's tism soothing to not """""waste""""" all those bits but no not unless they're in a big array or something

brap
Aug 23, 2004

Grimey Drawer

NihilCredo posted:

isn't the former PATCH and the second PUT?

my mental model was like this:

GET = select
PUT = upsert
DELETE = delete
PATCH = update
POST = generic "here's a command that should result in some (side) effects, let me know about them maybe"

yep, I just forgot about the existence of patch

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


prisoner of waffles posted:

More like the "very good programmers thread," amirite?


don't worry I just POST

akadajet
Sep 14, 2003

Powerful Two-Hander posted:

don't worry I just POST

tef
May 30, 2004

-> some l-system crap ->
just use get and post

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
get for everything unless you're a tryhard nerd

tef
May 30, 2004

-> some l-system crap ->
that breaks misconfigured poo poo and you can pack more data in a post

gonadic io
Feb 16, 2011

>>=
super super terrible programmer q:
i have an array of 6 elements, (the neighbours of a tile) which contain a bool, and i'm writing a function that returns if any 3 consecutive neighbours are true. it also has to wrap around so the first element is next to the last one

so [t, f, t, f, t, t] is true and [f,t,f,t,t,f] is false and [f,t,f,t,t,t] is true

the only way i can think of is to loop from 0 to 5 (and then to 0 again) and increment a counter if true and reset the counter if false. then return (counter >= 3).

e: poo poo but that doesn't work in the case of [t,t,t,f,f,f,f]. maybe early return if it's 3 or longer at any step?

gonadic io fucked around with this message at 16:24 on Oct 29, 2017

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
just count to 9 or whatever, then mod 6 for the index

gonadic io
Feb 16, 2011

>>=
god this is awful:
code:
fn has_seq_3_or_longer(neighbours: &[bool]) -> bool {
    let mut seq_length = 0;
    for neighbour in neighbours {
        if *neighbour {
            seq_length += 1
        } else {
            seq_length = 0
        }
        if seq_length >= 3 { return true; }
    };
    if neighbours[0] {
        seq_length += 1
    } else {
        seq_length = 0
    };
    return seq_length >= 3;
}

Fiedler
Jun 29, 2002

I, for one, welcome our new mouse overlords.

gonadic io posted:

god this is awful:
Agreed. Allman was right.

cinci zoo sniper
Mar 15, 2013




gonadic io posted:

super super terrible programmer q:
i have an array of 6 elements, (the neighbours of a tile) which contain a bool, and i'm writing a function that returns if any 3 consecutive neighbours are true. it also has to wrap around so the first element is next to the last one

so [t, f, t, f, t, t] is true and [f,t,f,t,t,f] is false and [f,t,f,t,t,t] is true

the only way i can think of is to loop from 0 to 5 (and then to 0 again) and increment a counter if true and reset the counter if false. then return (counter >= 3).

e: poo poo but that doesn't work in the case of [t,t,t,f,f,f,f]. maybe early return if it's 3 or longer at any step?

super terrible answer attempt: copy first 2 elements of array to the end, then while i <= length and true_counter < 3 do the increments on last match, starting with 1 and 2nd list element

cinci zoo sniper
Mar 15, 2013




oh also copy last two elements to the start

Shaggar
Apr 26, 2006

Fiedler posted:

Agreed. Allman was right.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

CRIP EATIN BREAD posted:

just count to 9 or whatever, then mod 6 for the index

ya do this op

code:
func has3Sequence(from neighbors: [Bool]) -> Bool {
    var count = 0
    for i in 0..<neighbors.count + 2 {
        if neighbors[i % neighbors.count] {
            if count == 2 {
                return true
            }
            count += 1
            
        } else {
            count = 0
        }
    }
    return false
}

carry on then fucked around with this message at 17:35 on Oct 29, 2017

Fiedler
Jun 29, 2002

I, for one, welcome our new mouse overlords.
Is there some reason that this shouldn't be generalized to sequences of an arbitrary length? Why is three special?

gonadic io
Feb 16, 2011

>>=

Fiedler posted:

Is there some reason that this shouldn't be generalized to sequences of an arbitrary length? Why is three special?

it's a lovely little game i'm writing so there's no need to generalise unless it'd improve the code.

Smoke_Max
Sep 7, 2011

I don't know about Rust, but I'd probably do this in Haskell. Maybe it can help you?

code:
neighbors3 :: [Bool] -> Bool
neighbors3 xs = 
    let cycled = cycle xs
        triples = zip3 cycled (tail cycled) (tail (tail cycled))
    in
        any (\(a, b, c) -> a && b && c) (take (length xs) triples)
code:
*Main> neighbors3 [True, False, True, False, True, True]
True
*Main> neighbors3 [True, False, True, True, True, False]
True
*Main> neighbors3 [True, False, True, True, False, False]
False

gonadic io
Feb 16, 2011

>>=
haskell has the built in group which groups by equality and i've never seen any use for until now

code:
neighbors3 :: [Bool] -> Bool
neighbors3 xs = any (\ys -> length ys >= 3) (filter head (group xs'))
	where xs' = xs ++ take 2 xs

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost

redleader posted:

ok so serverless computing/functions-as-a-service: when and why would I actually want to use these? why are these cool + good and why/when would using these services be a better alternative to normal computering?

lots of things you put in a message queue also go fine in a serverless dealio
which is good because message queues are founts of despair, especially doing ops for them

akadajet
Sep 14, 2003

tef posted:

just use get and post

code:

POST /api/deleteItem
{
  id: "foo"
}

gonadic io
Feb 16, 2011

>>=

akadajet posted:

code:
POST /api/deleteItem
{
  id: "foo"
}

I didn't realise that we worked together

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

gonadic io posted:

I didn't realise that we worked together

Soricidus
Oct 21, 2010
freedom-hating statist shill
I wish my coworkers designed apis that good

actionjackson
Jan 12, 2003

Hello I'm a biostatistician and I don't know any "real" languages, just SAS and R. Am I confined to the #datascience thread or can I post in YOSPOS tyia

MononcQc
May 29, 2007

lovely programmer solution with pattern matching:

match([true, true, true, _, _, _]) -> true;
match([_, true, true, true, _, _]) -> true;
match([_, _, true, true, true, _]) -> true;
match([_, _, _, true, true, true]) -> true;
match([true, _, _, _, true, true]) -> true;
match([true, true, _, _, _, true]) -> true.

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

MononcQc posted:

lovely programmer solution with pattern matching:

match([true, true, true, _, _, _]) -> true;
match([_, true, true, true, _, _]) -> true;
match([_, _, true, true, true, _]) -> true;
match([_, _, _, true, true, true]) -> true;
match([true, _, _, _, true, true]) -> true;
match([true, true, _, _, _, true]) -> true.
i liked the one with the missing comma

gonadic io
Feb 16, 2011

>>=
code:
if (arr[0]) {
    if (arr[1]) {
        if (arr[2]) {
            return true;
        }
    }
} elif (arr[1]) {
    if (arr[2]) {
        if (arr[3]) {
            return true;
        }
    }
} elif (arr[
:suicide:

Fiedler
Jun 29, 2002

I, for one, welcome our new mouse overlords.
code:
return n[0] && n[1] && n[2] ||
       n[1] && n[2] && n[3] ||
       n[2] && n[3] && n[4] ||
       n[3] && n[4] && n[5] ||
       n[4] && n[5] && n[0] ||
       n[5] && n[0] && n[1];

Sweevo
Nov 8, 2007

i sometimes throw cables away

i mean straight into the bin without spending 10+ years in the box of might-come-in-handy-someday first

im a fucking monster

instead of using an array of bools use an integer variable and bit masking to set/clear individual bits. then you can just test for a match to the six values

code:
switch(varname) // assume the six neighbours are in the lower six bits
{
    case 0b111000:
    case 0b011100:
    case 0b001110:
    case 0b000111:
    case 0b100011:
    case 0b110001:
        <code for match goes here>
        break;
    default:
        <code for non-match goes here>
}

gonadic io
Feb 16, 2011

>>=

Sweevo posted:

instead of using an array of bools use an integer variable and bit masking to set/clear individual bits. then you can just test for a match to the six values

code:

switch(varname) // assume the six neighbours are in the lower six bits
{
    case 0b111000:
    case 0b011100:
    case 0b001110:
    case 0b000111:
    case 0b100011:
    case 0b110001:
        <code for match goes here>
        break;
    default:
        <code for non-match goes here>
}
this won't work for 111100 which contains 3 concurrent 1s. sorry.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Sweevo posted:

instead of using an array of bools use an integer variable and bit masking to set/clear individual bits. then you can just test for a match to the six values

code:
switch(varname) // assume the six neighbours are in the lower six bits
{
    case 0b111000:
    case 0b011100:
    case 0b001110:
    case 0b000111:
    case 0b100011:
    case 0b110001:
        <code for match goes here>
        break;
    default:
        <code for non-match goes here>
}



code:
if (varname & 0b111000 == 0b111000 || 
varname & 0b011100 == 0b011100 ||
varname & 0b001110 == 0b001110 ||
varname & 0b000111 == 0b000111 ||
varname & 0b100011 == 0b100011 ||
varname & 0b110001 == 0b110001) {
    return true
}

return false

gonadic io
Feb 16, 2011

>>=
code:
macro_rules! butt {
    ($arr:expr, [$($x:expr),+]) => {
        $($arr[$x%6] && $arr[($x+1)%6] && $arr[($x+2)%6])&&+
    }
}

fn has_seq_3_or_longer(neighbours: &[bool]) -> bool {
    butt!(neighbours, [0, 1, 2, 3, 4, 5])
}
code:
> cargo rustc -- -Z unstable-options --pretty=expanded
        fn has_seq_3_or_longer(neighbours: &[bool]) -> bool {
            neighbours[0 % 6] && neighbours[(0 + 1) % 6] &&
                neighbours[(0 + 2) % 6] ||
                neighbours[1 % 6] && neighbours[(1 + 1) % 6] &&
                    neighbours[(1 + 2) % 6] ||
                neighbours[2 % 6] && neighbours[(2 + 1) % 6] &&
                    neighbours[(2 + 2) % 6] ||
                neighbours[3 % 6] && neighbours[(3 + 1) % 6] &&
                    neighbours[(3 + 2) % 6] ||
                neighbours[4 % 6] && neighbours[(4 + 1) % 6] &&
                    neighbours[(4 + 2) % 6] ||
                neighbours[5 % 6] && neighbours[(5 + 1) % 6] &&
                    neighbours[(5 + 2) % 6]
        }

gonadic io fucked around with this message at 22:14 on Oct 29, 2017

Adbot
ADBOT LOVES YOU

redleader
Aug 18, 2005

Engage according to operational parameters

akadajet posted:

code:

POST /api/deleteItem
{
  id: "foo"
}

i don't see anything wrong with this

  • Locked thread