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.
 
  • Post
  • Reply
Sedro
Dec 31, 2008

Shy posted:

Am I missing something or do JetBrains IDEs outside of DataGrip not offer SQL code formatting?

It works for me in IDEA, at least inside .sql files with Postgres dialect chosen. The lesser IDEs might not have it.

Adbot
ADBOT LOVES YOU

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
At the very least I think all JetBrains IDEs support the exact same plugins, so you should be able to find an SQL plugin for any IDE that doesn't have native support. I know several of their IDEs are still very barebones in terms of extra features, since they're focusing on core. CLion, for instance, only just started feeling like something that doesn't belong in alpha, and Goland honestly feels like it needs a lot of core work.

Dawncloack
Nov 26, 2007
ECKS DEE!
Nap Ghost
Not exactly programming but I am sure you can help me.

You are programming a videofame and the protagonist says "I have 27 gold".
The code in C (all I ever knew and now forgot) would say somethin like

Print &Gold " I have &gold gold" or something along those lines. I really don't remember.

So my question, how can I write the same thing in pseudocode sothat anyone, even the most computer illiterate person, can get what I mean?

As in, they get that there's a pre-written part and a part that's fetched from somewhere in the program? How can I make it glaringly obvious?

Thanks a lot!

VVV much appreciated, but I should have explained, I am not trying to explain code, it has to go on a sort of art project.

I am trying to mock procedurally generated things out there,like

"Why" $profile.age "is tje best age to start a career in" $latest.search "!". That I keep seeing.

I just want to find the most obvious way to put it, and it has to be in one instance, preferrably.

Dawncloack fucked around with this message at 14:07 on Feb 15, 2018

candide
Jun 16, 2002

The Tipping Point
Might help to repeat examples with different inputs. Here's something that's really close to valid Python syntax that might get the point across.

code:
name = John
money = 100
print "Hi I am {0} and I have {1} dollars" % (name, money)
---
Hi I am John and I have 100 dollars


name = Jane
money = 79
print "Hi I am {0} and I have {1} dollars" % (name, money)
---
Hi I am Jane and I have 79 dollars

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Dawncloack posted:

Not exactly programming but I am sure you can help me.

You are programming a videofame and the protagonist says "I have 27 gold".
The code in C (all I ever knew and now forgot) would say somethin like

Print &Gold " I have &gold gold" or something along those lines. I really don't remember.

So my question, how can I write the same thing in pseudocode sothat anyone, even the most computer illiterate person, can get what I mean?

As in, they get that there's a pre-written part and a part that's fetched from somewhere in the program? How can I make it glaringly obvious?

Thanks a lot!

VVV much appreciated, but I should have explained, I am not trying to explain code, it has to go on a sort of art project.

I am trying to mock procedurally generated things out there,like

"Why" $profile.age "is tje best age to start a career in" $latest.search "!". That I keep seeing.

I just want to find the most obvious way to put it, and it has to be in one instance, preferrably.

C#
code:
Console.Writeline($”why {profile.age} ...”);
Console.Writeline(String.Format(“why {0} ...”, profile.age, ...);
Really though the programming set will get it no matter what; most of the rest have never seen code. I’d probably focus on making the substitutions visually distinct (bold? font?) in addition to whatever token you throw around for them ($-prefix is fine even if it reminds me of Perl)

raminasi
Jan 25, 2005

a last drink with no ice

Dawncloack posted:

Not exactly programming but I am sure you can help me.

You are programming a videofame and the protagonist says "I have 27 gold".
The code in C (all I ever knew and now forgot) would say somethin like

Print &Gold " I have &gold gold" or something along those lines. I really don't remember.

So my question, how can I write the same thing in pseudocode sothat anyone, even the most computer illiterate person, can get what I mean?

As in, they get that there's a pre-written part and a part that's fetched from somewhere in the program? How can I make it glaringly obvious?

Thanks a lot!

VVV much appreciated, but I should have explained, I am not trying to explain code, it has to go on a sort of art project.

I am trying to mock procedurally generated things out there,like

"Why" $profile.age "is tje best age to start a career in" $latest.search "!". That I keep seeing.

I just want to find the most obvious way to put it, and it has to be in one instance, preferrably.

You might look for inspiration here. I agree that formatting is going to be at least as important as syntax for what you're doing though.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Something like "I have [amount of] gold" or "Why [age] is the best age to start a career in [field]!" perhaps?

Sad Panda
Sep 22, 2004

I'm a Sad Panda.
http://www.ocr.org.uk/Images/202654-pseudocode-guide.pdf

That's the pseudocode guidelines for the main Computing exam board here in the UK.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Dawncloack posted:

I am trying to mock procedurally generated things out there,like

"Why" $profile.age "is tje best age to start a career in" $latest.search "!". That I keep seeing.

I just want to find the most obvious way to put it, and it has to be in one instance, preferrably.

Portal did this by having GlaDOS say things like "You must be the pride of [INSERT SUBJECT HOME TOWN]! I bet everyone in [INSERT SUBJECT HOME TOWN] is proud of your accomplishments."

JawnV6
Jul 4, 2004

So hot ...
City Name
Sports Team

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Using a computery typeface will probably help too, so it has that sense of a robot voice butting in

Shy
Mar 20, 2010

Sedro posted:

It works for me in IDEA, at least inside .sql files with Postgres dialect chosen. The lesser IDEs might not have it.

Joda posted:

At the very least I think all JetBrains IDEs support the exact same plugins, so you should be able to find an SQL plugin for any IDE that doesn't have native support. I know several of their IDEs are still very barebones in terms of extra features, since they're focusing on core. CLion, for instance, only just started feeling like something that doesn't belong in alpha, and Goland honestly feels like it needs a lot of core work.

Setting a project dialect made it work for project files, so apparently no plugins required but needs some customization unlike DataGrip.

Pollyanna
Mar 5, 2005

Milk's on them.


Okay, so there was a graph theory question in a recent Amazon technical screening that I failed on. I want to try it again without the pressure of an interview and get some advice on solving this motherfucker.

Given any node in a particular tree, get its right sibling if it exists, or nothing (null) if it does not exist. The tree looks like this:

code:
          1
         / \
        2 > 3
       /   / \
      4 > 5 > 6
And the expected results are something like this:

  • 1 -> null
  • 2 -> 3
  • 3 -> null
  • 4 -> 5
  • 5 -> 6
  • 6 -> null

I understand the fact that each node has an optional parent, left child, and right child.

Let's start with the base case: the root (1). 1 does not have a parent, so it cannot have any siblings. So that's our first rule:

code:
# pseudocode
if node.parent == null:
  return null
Let's move onto our next case: 2. 2 does have a parent, so that means it can theoretically have a right sibling. Finding the right sibling depends on getting the parent, and if the parent exists, getting that parent's right child. That expands our code to this:

code:
if node.parent == null:
  return null  # 1 -> null
else:
  return node.parent.right  # 2 -> 3, 5 -> 6
This also covers the case of 5.

Our next case is 3. 3 does have a parent, but it is already its parent rightmost child, so it can't have a rightmost sibling. Our code now looks like this:

code:
if node.parent == null:
  return null  # 1 -> null
else:
  if node.parent.right != node
    return node.parent.right  # 2 -> 3
  else:
    return null  # 3 -> null, 6 -> null
This also covers the case of 6.

Now we get to deal with the black sheep of the family that is node 4. (Been there.) Node 4 is a funny one in that it has a parent with no right child, yet it has a right sibling in 5. So clearly, our "if parent has no right child then no right sibling" assumption is wrong, and there's a more complicated solution.

4 does have a right sibling. The reason for this is that 4's parent 2 does not have a right child, but 2's parent 1 has a right child 3 that has a left child 5. So it looks like if your node's parent does not have a right child, you need to:

1. Go up until you find a parent that does have a right child that isn't the same as the original node
2. From that right child, select each left child until you reach the same level of depth as the original node

So it's something like...

code:
let right_child = node.parent.right
while right_child == null
  let working_node = node.parent
  if node.parent
  # what
I'm a little stuck here. I get that I need to do this in a bit of a looping or maybe even recursive fashion, but I'm not sure how to go about doing that. Anyone got advice for implementing this?

nielsm
Jun 1, 2009



To get a right sibling, you need to walk upwards, eventually arrive from a left branch, then walk down the right branch.

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
I'm probably wrong, but I think a breadth-first search would be the core algorithm?

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

ynohtna posted:

I'm probably wrong, but I think a breadth-first search would be the core algorithm?

No, nielsm has the right of it. You know the trick for navigating mazes where you just keep your right hand on the wall? It's the same principle, you just need to be able to recognize when to walk up, when to walk down, and when you've reached the correct depth.

Caganer
Feb 15, 2018
Is there an easy way to convert an image from png to gif?

With google images dropping "view image" I had a hacky idea:

Take screenshot

Run a script that converts most recent screenshot from png (usually huge for anything photographic) to a high quality jpg (like a 9 on the photoshop slider)

is this possible in say, python?

Dawncloack
Nov 26, 2007
ECKS DEE!
Nap Ghost

TooMuchAbstraction posted:

Portal did this by having GlaDOS say things like "You must be the pride of [INSERT SUBJECT HOME TOWN]! I bet everyone in [INSERT SUBJECT HOME TOWN] is proud of your accomplishments."

Yeah that was one of my favorite details of the entire game.

nielsm
Jun 1, 2009



There's many ways to convert between image formats, and lots of stand-alone programs that can do it.

On Windows, IrfanView is a decent, light-weight image viewer that can also convert, and has batch functionality. Pure GUI program.

Cross-platform, there is the suite of command-line tools ImageMagick, the main component is a program called "convert". So you can run a command like "convert inputfile.png outputfile.gif", and it does just that.

And you can find bindings for tons of different image processing libraries for pretty much any programming language. Python for example has a binding for ImageMagick, or Pillow which is forked from the classic PIL (Python Imaging Library).

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Caganer posted:

Is there an easy way to convert an image from png to gif?

With google images dropping "view image" I had a hacky idea:

Take screenshot

Run a script that converts most recent screenshot from png (usually huge for anything photographic) to a high quality jpg (like a 9 on the photoshop slider)

is this possible in say, python?

download imagemagick, just do

code:
magick convert rose.png rose.jpg
efb

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

TooMuchAbstraction posted:

No, nielsm has the right of it. You know the trick for navigating mazes where you just keep your right hand on the wall? It's the same principle, you just need to be able to recognize when to walk up, when to walk down, and when you've reached the correct depth.

Yeah, but that's exactly what it means to do a breadth first search, to go back up and down to capture nodes at the same depth when walking the tree, before going down to another level. At any point what Pollyanna wants is the next node [at the same level] that would be checked in a breadth first search.

Nippashish
Nov 2, 2005

Let me see you dance!

Caganer posted:

With google images dropping "view image"

Right click on the image in the expanded preview and copy image address.

Caganer
Feb 15, 2018

Bruegels Fuckbooks posted:

download imagemagick, just do

code:
magick convert rose.png rose.jpg
efb

but will that optimize use of the jpg algo? I've found that adjusting from max rs to say 9/12 really knocks the filesize down.

JawnV6
Jul 4, 2004

So hot ...

Caganer posted:

but will that optimize use of the jpg algo? I've found that adjusting from max rs to say 9/12 really knocks the filesize down.

probably

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
ImageMagick is a huge, thoroughly-established library. If your problem involves images, it can do it, though you might have to pull in ffmpeg if you're working with video streams.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.



How exactly are you defining "right sibling"? I think that if you have the definition nailed down precisely, then it's much easier to write the code.

Methanar
Sep 26, 2013

by the sex ghost
What is the proper way of working with go templates and yaml in general.


I'm doing some changes to kubernetes helm charts and trying to keep track of what the gently caress I'm doing in vanilla vim is impossible and obviously stupid way of doing it. I don't even know how to test the changes I've made yet

Caganer
Feb 15, 2018

TooMuchAbstraction posted:

ImageMagick is a huge, thoroughly-established library. If your problem involves images, it can do it, though you might have to pull in ffmpeg if you're working with video streams.

Cool I’ve been trying to find a small programming project this looks like a good fit

Nude
Nov 16, 2014

I have no idea what I'm doing.
So I think I got what signed and unsigned mean for things like int, floats, etc. which is signedunsigned can go from 0-byte max. While unsignedsigned halves the byte max number to include both positive and negative.

But why is it called signed and unsigned? It seems like to me a poor choice of name to describe that kind of behavior. And is it just a coincidence that we use signed and unsigned to describe valid applications as well?

Nude fucked around with this message at 16:32 on Feb 17, 2018

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Nude posted:

But why is it called signed and unsigned?

Not gospel, but I assume because you are taking the high bit away from the numeric representation and using it as the sign bit. A number with a sign bit is signed, a number without a sign but is unsigned.

Nude
Nov 16, 2014

I have no idea what I'm doing.

ulmont posted:

Not gospel, but I assume because you are taking the high bit away from the numeric representation and using it as the sign bit. A number with a sign bit is signed, a number without a sign but is unsigned.

Oh okay it seems in my example I confused the two, this makes sense and also makes it easy to remember which is which thanks.

nielsm
Jun 1, 2009



Nude posted:

So I think I got what signed and unsigned mean for things like int, floats, etc. which is signed can go from 0-byte max. While unsigned halves the byte max number to include both positive and negative.

But why is it called signed and unsigned? It seems like to me a poor choice of name to describe that kind of behavior. And is it just a coincidence that we use signed and unsigned to describe valid applications as well?

You got it flipped. Unsigned is from 0 to a maximum, signed is from negative to positive with 0 in the middle.

The term comes from plus sign and minus sign: A value which can have a plus sign or minus sign is just called signed. And contrarily, an unsigned number does not have a sign and is generally assumed to always be positive.

An 8 bit unsigned number can have values from 0 to 28-1 (i.e. 255), while an 8 bit signed number in two's complement representation can have values from -(27) to 27-1 (i.e. -128 to +127). There's 256 different values possible regardless of whether it's signed or unsigned, it just affects how the binary representation is interpreted.

mystes
May 31, 2006

Nude posted:

So I think I got what signed and unsigned mean for things like int, floats, etc. which is signed can go from 0-byte max. While unsigned halves the byte max number to include both positive and negative.

But why is it called signed and unsigned? It seems like to me a poor choice of name to describe that kind of behavior. And is it just a coincidence that we use signed and unsigned to describe valid applications as well?
Probably because "sign" is a term used to refer to whether a number is positive or negative? https://en.wikipedia.org/wiki/Sign_(mathematics)

Nude
Nov 16, 2014

I have no idea what I'm doing.
Thanks guys! Yeah I don't know why I couldn't see that connection, but I appreciate your answers. Clears it right up.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Nude posted:

So I think I got what signed and unsigned mean for things like int, floats, etc. which is signedunsigned can go from 0-byte max. While unsignedsigned halves the byte max number to include both positive and negative.

But why is it called signed and unsigned? It seems like to me a poor choice of name to describe that kind of behavior. And is it just a coincidence that we use signed and unsigned to describe valid applications as well?

There is no unsigned float. By definition, they have a bit reserved for their sign.

ufarn
May 30, 2009
Is there a way to return some version of `ls -s` where the values are relative to 100% rather than MB/GB/B? Eg:

code:
ls
100% foo
 90% bar
 90% baz
 50% qux

csammis
Aug 26, 2003

Mental Institution

ufarn posted:

Is there a way to return some version of `ls -s` where the values are relative to 100% rather than MB/GB/B?

"Relative to 100%" doesn't mean anything...do you mean size as a percentage of the size of the largest entry in the listing? So if I have three files 10MB 5MB and 1MB I'd receive a listing like 100% 50% 10% ? `ls` can't do that but it seems like it wouldn't be too hard to write a script which can accept a listing and output what you want.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
code:
import os
import shutil

item_sizes = []
for item in os.listdir(path):
  item_sizes.append((item, shutil.stat(item).st_size)  # Size in bytes
item_sizes.sort(lambda i: i[1])  # Sort by file size
for item, bytes in item_sizes:
  print("%s: %.2f%%", item, bytes * 100.0 / item_sizes[-1][1])

mystes
May 31, 2006

Comedy option:
code:
ls | sed 's/$/ 100%/'
Now all the sizes are relative to 100%.

By the way, ufarn, are you sure you don't just want something that computes total folder sizes recursively like baobob or ncdu rather than just converting the sizes to percentages?

mystes fucked around with this message at 19:44 on Feb 18, 2018

Adbot
ADBOT LOVES YOU

ufarn
May 30, 2009

mystes posted:

Comedy option:
code:
ls | sed 's/$/ 100%/'
Now all the sizes are relative to 100%.

By the way, ufarn, are you sure you don't just want something that computes total folder sizes recursively like baobob or ncdu rather than just converting the sizes to percentages?
It's only for some basic benchmarking for image compression and the like, so something more nested like du/ds seems too elaborate. I just saw some people doing it in their tests and wondered how they did it, and almost assumed it was a straightforward UNIX command or pipe.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply