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
mystes
May 31, 2006

ufarn posted:

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.
If you know the specific file you want to compare to, then it's simpler and you can do it with awk or whatever if you really must.

Something like this, which takes the name of the file to use as the reference for the 100% size as an argument, seems to work, although I'm terrible at shell scripting and don't understand awk syntax at all and it will probably burn down your computer.
code:
#!/bin/bash
ORIG_SIZE=$(ls -s "$1" | awk '{print $1}')
ls -s --sort=size | tail -n +2 | awk -v ORIG_SIZE=$ORIG_SIZE '{$1 = 100*$1/ORIG_SIZE "%"} {print}'
Actually even if you just want the comparison made to the largest file you could probably do that in awk somehow if you hate yourself.

mystes fucked around with this message at 21:32 on Feb 18, 2018

Adbot
ADBOT LOVES YOU

Pollyanna
Mar 5, 2005

Milk's on them.


ultrafilter posted:

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.

Same depth, one "unit" to the right. I don't know, ask Amazon.

Even with nielsm's help, I have no idea how to solve it. I think I need a course to help me learn data structures and algorithms, especially graph poo poo. Anyone got recommendations for a MOOC I can take or something? I learn best under structure.

nielsm
Jun 1, 2009



Here's an untested solution to the right sibling problem in Python: https://puu.sh/zrdEv/a6d725d8d5.txt

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Pollyanna posted:

Same depth, one "unit" to the right. I don't know, ask Amazon.

The point of the problem is to be able to define "right sibling" rigorously! Amazon ain't gonna tell you.

Hint: how do you define whether something is to the left or the right of something else? What does "1 unit" translate to?

Pollyanna
Mar 5, 2005

Milk's on them.


Suspicious Dish posted:

The point of the problem is to be able to define "right sibling" rigorously! Amazon ain't gonna tell you.

I defined right sibling as rigorously as I could (I have no idea what I'm doing in graph problems), but whether or not that definition is correct/"okay" is up to the interviewer as they are judging me. I did make sure to hash out the definition alongside the interviewer and make sure they understood where I was going. Regardless, this is a set of right siblings:

code:
          1
         / \
        2 > 3
       /   / \
      4 > 5 > 6
3 is a right sibling of 2.
5 is a right sibling of 4.
6 is a right sibling of 5.

nielsm posted:

Here's an untested solution to the right sibling problem in Python: https://puu.sh/zrdEv/a6d725d8d5.txt

So you do need to manually keep track of the level you've gone down/depth? You can't put together an algorithm that doesn't need to know about the depth? That's actually quite complicated...but I'll bash my head against this until I understand.

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

Pollyanna posted:

Same depth, one "unit" to the right. I don't know, ask Amazon.

Here's a full tree (I tried ok) with all slots filled

pre:
            A
         /      \
        /        \
       /          \
      B            C
    /  \          /  \
   /    \        /    \
  D      E      F      G
 / \    / \    / \    / \
H   I  J   K  L   M  N   O
assuming "one unit to the right" means literally the adjacent slot (no ignoring unfilled ones), you have two options
  • you're on a "left" node, so its Right Sibling (RS) is the parent's right child
  • you're on a "right" node, so its RS is the left child of the node that's directly to the right of your parent (by definiton, its RS)

So for H, that's easy - left node, get the right node of your parent, that's I

For I - its a right node, need to find the RS of your parent (D)
For D - it's a left node, easy again - right child of the parent is E
Back to I - the left child of E is J, so that's your RS of I

Try it with K, it's basically a recursive algorithm, based on a couple of simple rules

e- just to pseudocode this since it's probably clearer
code:
recursive fun getRightSibling(node):
  node.parent == null ->
    return null
  node == node.parent.leftChild ->
    return node.parent.rightChild
  node == node.parent.rightChild ->
    return getRightSibling(node.parent).leftChild

baka kaba fucked around with this message at 20:09 on Feb 19, 2018

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


As asked, this is a little bit of a bad question, because there is a standard notion of when two nodes are siblings and that's not what's being asked for here. I would've lost some time clarifying exactly what the interviewer was asking for.

(Two nodes are siblings if and only if they have the same parent, in case you're wondering.)

Pollyanna posted:

So you do need to manually keep track of the level you've gone down/depth? You can't put together an algorithm that doesn't need to know about the depth? That's actually quite complicated...but I'll bash my head against this until I understand.

Yeah. What the interviewer seems to be asking for here is the least value in the tree such that it's greater than a given value and that the node storing it is at the same depth as the node storing the given value. There's no way to calculate that without somehow storing depth.

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

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

Pollyanna posted:

So you do need to manually keep track of the level you've gone down/depth? You can't put together an algorithm that doesn't need to know about the depth? That's actually quite complicated...but I'll bash my head against this until I understand.

You could probably come up with an algorithm that implicitly keeps track of depth, for example a breadth-first search that starts from the top of the tree. But that would have poor memory scaling (you need to keep an entire depth level of the tree in your search stack at a time) and runtime scaling (you examine an awful lot of the tree that's completely irrelevant to your search, since you don't start from the node you want the neighbor of), so if a candidate handed me that as a solution, the obvious next question would be to ask them to come up with a solution with better performance.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
You can also track depth implicitly by the depth of your call stack frame (yay recursion).

One other way to phrase nielsm's intuition: make a single "right turn" the first time you can, which is when you arrive from a left child. If you get to the root and you arrived from the right, you can't turn right, since otherwise you would have done so already, so return null. From there, traverse down the rest of the tree left-first. If your tree has gaps (e.g. a node with one child), treat the child as a right-child on the way up (don't try to turn right), and a left-node on the way down (take the only path you can).

nielsm
Jun 1, 2009



Pollyanna posted:

3 is a right sibling of 2.
5 is a right sibling of 4.
6 is a right sibling of 5.
Yes but why?
1) Something with common parents and left/right side relationships.
2) Nodes B is the next right sibling to node A if and only if nodes A and B have a common parent where node A is on the left branch and node B on the right branch...

Pollyanna posted:

So you do need to manually keep track of the level you've gone down/depth? You can't put together an algorithm that doesn't need to know about the depth? That's actually quite complicated...but I'll bash my head against this until I understand.

You can probably write a single recursive function that solves it without explicitly having a "depth" variable counting, but then you'd still implicitly keep track of the depth simply by the fact that there is a stack whose depth you can count.

Whoops yeah there's a bug I didn't think of.

nielsm fucked around with this message at 19:30 on Feb 19, 2018

Pollyanna
Mar 5, 2005

Milk's on them.


Seriously, genuinely, all I was given was this:

quote:

code:
          1
         / \
        2 > 3
       /   / \
      4 > 5 > 6
Come up with an algorithm that gives me the node to the right of each node, where 5 is to the right of four, <etc>

Maybe I hosed up by calling them siblings, I dunno.

As for the responses, I will reflect on this problem and wrap my head around it.

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

Honestly there's so many questions about that diagram, it seems like a big part of them posing it is seeing how you work through it, what questions you ask and how you come to some kind of concrete spec to implement

e-
/4\D+(\d+)/ :v:

baka kaba fucked around with this message at 20:28 on Feb 19, 2018

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

baka kaba posted:

Honestly there's so many questions about that diagram, it seems like a big part of them posing it is seeing how you work through it, what questions you ask and how you come to some kind of concrete spec to implement

e-
/4\D+(\d+)/ :v:

writing a function to print the tree with annotations on L and R nodes then a sed script sounds like an awesome way to solve the problem while likely failing the interview.

on the plus side, it would be a solution they hadn't seen before.

Faith For Two
Aug 27, 2015
I want to copy text from cells in a google doc spreasheet but it says: "Options to download, print, and copy have been disabled on this file."

I use a particular spreadsheet a lot at work and I often have to copy the text from the cells and put it in another tab to fill out forms. To do this, I've been doing ctrl+c on the text in the formula bar, or manually typing what's in the cell.

Obviously I don't "own" this file, so is there a way around this with a google spreadsheet api?

Things I've tried so far:
spreadsheet api: This looked promising https://stackoverflow.com/questions/4509336/how-to-copy-a-row-from-one-google-spreadsheet-to-another-google-spreadsheet-usin
but when I typed "var ss = SpreadsheetApp.getActiveSpreadsheet();" into the console, I got "VM298:1 Uncaught ReferenceError: SpreadsheetApp is not defined at <anonymous>:1:10"

inspecting html element: I can't seem to find the data within the cells, so I don't think I'd be able to copy data from a range of cells based on the html elements.
I'm probably going to try this though:
If I highlight a single cell, the text in the cell appears in the formula bar. I can find that text using html id t-formula-bar-input. Then I could write a script to copy/append the data into a string, repeat the process for every cell I need, and then copy the string to the clipboard.
^sorry about that; I came up with that idea as I was writing this post down.

I guess my question remains:
can I use an api or something to copy data from a range of cells in a google spreadsheet that has restrictions on downloading, printing, and copying.

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
Have you considered asking whoever owns the sheet to give you less-restricted access?

Faith For Two
Aug 27, 2015

TooMuchAbstraction posted:

Have you considered asking whoever owns the sheet to give you less-restricted access?

I guess I could try that too.

Dominoes
Sep 20, 2007

Hey dudS. Learning C. For context, I'm fluent N Python, A modern JS.

So far, it seems similar to Python, but W curly bracS, semicolons, verbose loops, enforcD type decs, A fewer/more-basic builtin funcNs A data structurS. (ie doesn't have neat thGs like comprehensions, map/filter, loads F helpR methods etc) FM WT I've heard, it's supposD to B much more difficult TN this cursory examinaN indicatS; ie loads F memory-management etc.

My suspicion is TT TS memory-management liS in T finR-points F pointers/malloc/free. Is TS T case? WT else am I missG?

Dominoes fucked around with this message at 14:42 on Feb 23, 2018

Volguus
Mar 3, 2009

Dominoes posted:

Hey dudS. Learning C. For context, I'm fluent N Python, A modern JS.

So far, it seems similar to Python, but W curly bracS, semicolons, verbose loops, enforcD type decs, A fewer/more-basic builtin funcNs A data structurS. (ie doesn't have neat thGs like comprehensions, map/filter, loads F helpR methods etc) FM WT I've heard, it's supposD to B much more difficult TN this cursory examinaN indicatS; ie loads F memory-management etc.

My suspicion is TT TS memory-management liS in T finR-points F pointers/malloc/free. Is TS T case? WT else am I missG?

A keyboard.

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

Uh that post wasn't like that before. C exposure works fast huh

mystes
May 31, 2006

Dominoes posted:

Hey dudS. Learning C. For context, I'm fluent N Python, A modern JS.

So far, it seems similar to Python, but W curly bracS, semicolons, verbose loops, enforcD type decs, A fewer/more-basic builtin funcNs A data structurS. (ie doesn't have neat thGs like comprehensions, map/filter, loads F helpR methods etc) FM WT I've heard, it's supposD to B much more difficult TN this cursory examinaN indicatS; ie loads F memory-management etc.

My suspicion is TT TS memory-management liS in T finR-points F pointers/malloc/free. Is TS T case? WT else am I missG?
If forums were like C, this post would compile with no warnings and then immediately segfault.

Dominoes
Sep 20, 2007

I'm working on a system of 1-1mapped, human-readable shorthand using only standard chars; didn't intend it to be this distracting. Unfortunately, it's only saving about 10% of chars.

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

Jst drp ll th vwls

Dominoes
Sep 20, 2007

Shorter and still easy to read, but has ambiguities. eg 'll' without context could be 'ill'; 'jst' → 'joust'; 'drp' → 'drip', but in this case it's unambiguous.

I'm bills dip on a linked lust tutorial; abstract, bat note us beed is monads.

Dominoes fucked around with this message at 18:33 on Feb 23, 2018

Eela6
May 25, 2007
Shredded Hen

Dominoes posted:

I'm working on a system of 1-1mapped, human-readable shorthand using only standard chars; didn't intend it to be this distracting. Unfortunately, it's only saving about 10% of chars.

premature optimization...

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

Yeah but like, you're using T for The Tha Thi and also ending t's too. You could just address ambiguities where they appear, right?

I mean I'm guessing there's a ton of analysis and research on this kind of thing anyway. I wonder if anyone's made a compression algorithm based on that observation taht sectneens are rbladee if you jblume up the wdros but keep the fsrit and lsat lrtetes in pcale

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

baka kaba posted:

I mean I'm guessing there's a ton of analysis and research on this kind of thing anyway. I wonder if anyone's made a compression algorithm based on that observation taht sectneens are rbladee if you jblume up the wdros but keep the fsrit and lsat lrtetes in pcale

The value in compressing visual text tends to be slim to none, especially considering how badly it tends to gently caress up non-native or dyslexic readers.

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

Hey I didn't say it would be good or anything! I was just wondering if being able to reduce the middle of words to a set of unordered characters would make for good pattern-based compression

Pixelboy
Sep 13, 2005

Now, I know what you're thinking...

Pollyanna posted:

Anyone got recommendations for a MOOC I can take or something? I learn best under structure.

You should know all of this: https://www.coursera.org/specializations/data-structures-algorithms

The Fool
Oct 16, 2003


https://techdevguide.withgoogle.com/

This is also a thing that exists.

raminasi
Jan 25, 2005

a last drink with no ice

baka kaba posted:

sectneens are rbladee if you jblume up the wdros but keep the fsrit and lsat lrtetes in pcale

This is only true if a human hand-scrambles the words. If you actually automate the process the text comes out much less readable. (Which is certainly an interesting observation on its own.)

salted hash browns
Mar 26, 2007
ykrop
Dumb little question: I have a digitalocean box that runs a number of personal docker services for me. Checking websites, some alerts, things like that. Is there a dumb CI service I can use to automatically deploy docker containers from github with no fuss? Doesn't need to scale, personal use only.

Currently when I make a change I git push my changes to github, then ssh into my droplet and git pull then manually restart the container. Ideally, I would like to just git push and have the container get the lastest version and redeploy itself.

I've googled but haven't found a good solution, I figure something like this already should already exist?

Woodsy Owl
Oct 27, 2004

salted hash browns posted:

Dumb little question: I have a digitalocean box that runs a number of personal docker services for me. Checking websites, some alerts, things like that. Is there a dumb CI service I can use to automatically deploy docker containers from github with no fuss? Doesn't need to scale, personal use only.

Currently when I make a change I git push my changes to github, then ssh into my droplet and git pull then manually restart the container. Ideally, I would like to just git push and have the container get the lastest version and redeploy itself.

I've googled but haven't found a good solution, I figure something like this already should already exist?

cron job to git pull and check head commit hash against the hash of the branch currently deployed. If different do your redeploy logic.

Edit: cron, not corn

Dominoes
Sep 20, 2007

Yo dudes; looking for thoughts on learning Rust vs C as a low-level language. I'm learning a LL lang to improve my knowledge of programming in general, and to add another tool to the kit.

Most guides, in comparison, emphasize Rust's compile-time memory safety over C; and C/++'s widespread-use.

My impressions: Rust seems like the nicer language, aided by learning from the faults of earlier languages like C. Eg its package-management system, deliberate decisions to change the way memory-management is handled, addition of functional-language concepts like pattern-matching, implicit type determination in some cases, centralized documentation etc.

Is my initial assessment correct? Ie disregarding existing code or career options, Rust is a better language.

Related: Rust's official Book, (v2) is the best language-tutorial I've used. Context: I fit in its target demographic, of someone experienced with programming, but not necessary low-level.

Dominoes fucked around with this message at 13:10 on Mar 3, 2018

spiritual bypass
Feb 19, 2008

Grimey Drawer
Yes, Rust and Go were created specifically to address the shortcomings of C and C++ without sacrificing much in terms of performance or control. I don't know about Rust, but Go even allows you to inline asm, although I'm not sure when it would be a good idea.

I saw this talk about it a few days ago and found it really impressive:
https://www.youtube.com/watch?v=KINIAgRpkDA&t=1s

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Not entirely sure what you’re asking. Rust came out decades later and didn’t explicitly reject a lot of the learning people did about programming languages in the meantime, so it’s probably a nicer language to learn. Fewer people use it right now, if that matters to you.

In comparison, decades of failsons have learned C and think that’s the only way other people should be allowed to learn too, so you’ll get a lot of harebrained opinions about how vital it is for you to learn C or you’re not a real programmer etc. Those opinions can be discarded. That said, you probably will learn stuff if you pick up C instead of or in addition to Rust.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


tl;dr: Rust is probably a better choice if you just want to play around a bit, but there are good reasons to learn C.

First off, Rust is a systems programming language, but it isn't a particularly low-level language. It's very performance-oriented and it lets you do systems programming, but it still abstracts away a lot of the details of the underlying machine. If you want to peel back that particular veil, C is the right choice. To really see what's going on at a machine level, take a look at Patt & Patel. It would take a while to get through, but you'd learn a lot from doing it.

If you're not that interested in the guts of the computer and you just want to dabble in systems programming, then Rust is a better choice just because the various high-level features it has make it a lot more pleasant to program in than C. On the other hand, if you decide that you're interested in doing more, there are good reasons to learn C and eventually C++. First, there's a lot more C and C++ code out there than there is Rust code--probably a few orders of magnitude. In terms of getting a job, Rust is still a little bit of a gamble. Second, as performance-oriented as Rust is, C++ as written by someone who really knows what they're doing is still the gold standard for high performance computing. There are a lot of people trying to get that level of performance out of a higher-level language, but it's a hard problem and I don't think it'll be solved any time soon.

All that said, C has no features. There are the basic control flow structures, structs, header files, and a handful of standard library functions (mostly malloc and free). If you have prior programming experience, then getting to the point where you can write small programs and read larger ones will take you somewhere between a few hours and half a week. Why not spend some time learning both?

ultrafilter fucked around with this message at 17:21 on Mar 3, 2018

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
If you are writing a real program, or learning a language to write real programs in, then there are all sorts of reasonable arguments for different languages, but Rust is a very acceptable choice.

If you are learning a low-level programming language to try to understand computers better, you should learn C. C has a lot of things that will get in your way because it is not a great language, but Rust has a lot of things that will get in your way because it is trying to prevent you from doing dumb things. Spending two hours with a debugger and a disassembler trying to understand why those dumb things broke your program will teach far you more about computers than writing 10,000 lines of clean, idiomatic Rust that work perfectly once they compile at all and where all the ugliness is hidden behind the library's abstractions.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I never know where to point people who are already programmers who want to learn C to understand computers better. I "learned" C from various blog posts and tutorials and that wasn't great.

So what should such a person read?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
I honestly like K&R; it’s quite good at walking you through the language, it conveys the mindset of late-70s language design quite well, and enough of what it says is going to feel dated and questionable that you will not feel too tempted to take it to heart. Nobody should be learning C as their first language anymore.

It’s like Song of the South, there are lots of things to appreciate but it needs to be watched with a critical eye and you probably shouldn’t show it to kids.

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

Thanks for the info dudes! I'm tempted to dive back into C after attempting a project with Rust.

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