variable-assignment

Want to check whether a command succeeded by redirecting its output to a variable

自古美人都是妖i 提交于 2019-12-04 15:33:57
问题 I'm currently writing a bash script which loads video files up to to YouTube using GoogleCL. As I'm doing this uploading stuff in a loop (because there can be multiple video files) I would like to check if each file had been uploaded successfully before I upload the next one. The command google youtube post --access unlisted --category Tech $f (where $f represents the file) outputs a string which tells me whether the upload has been successful or not. But I don't know how to redirect that

What is this assignment construct called? And can you do it in Php?

瘦欲@ 提交于 2019-12-04 14:00:19
I have often used the following construct in Javascript: var foo = other_var || "default_value"; In Javascript, if the left side is falsy, then the value on the right side is assigned. It is very handy, and saves writing longer and unnecessarily explicit ternary expressions. Is there a name for this sort of construct ? Bonus: Is there a trick to do this in Php without using a ternary operator? PS: another variant is to throw an error if you don't get a truthy value, instead of giving a default value: var foo = something || alert("foo is not set!"); The logical-or (usually || ) operator is

scala zip list to tuple

旧城冷巷雨未停 提交于 2019-12-04 13:17:37
Working with JodaTime, trying to convert a List[LocalDate] to Tuple2[JodaTime, JodaTime] so I can do multi-assigment like so: val(expire, now) = List(row.expireDate, new JodaDate) zip (_.toDateTimeAtStartOfDay.getMillis) which of course does not compile. Is there a similarly concise way to do the above? I know I can just do it manually: val(expire, now) = (row.expireDate.toDateTimeAtStartOfDay.getMillis, new JodaDate().toDateTimeAtStartOfDay.getMillis) but that's a bit ugly val Seq(expire, now) = Seq(row.expireDate, new JodaDate).map(_.toDateTimeAtStartOfDay.getMillis) What you want (assuming

Need pairing algorithm - based on Hungarian?

只谈情不闲聊 提交于 2019-12-04 12:17:57
问题 Hungarian or Kuhn-Munkres algorithm (good description here) pairs objects from two sets (of n and m objects respectively, n>=m ) so that the overall "difference" (or "cost" of assignment) between paired objects be minimal. One feature of the algo doesn't suit me however: it does only exhaustive pairing, in the sense that it will pair all m objects with some of n objects. Instead of this, I'd want to be able to create arbitrary number k of pairs ( k<=m ) with overall cost minimal. For example,

Passing common title to all view and models CodeIgniter

三世轮回 提交于 2019-12-04 06:27:24
问题 I have this controller <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Main extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->helper('text'); } public function index() { $this->home(); } public function home() { $data['title']="Somesite"; $this->load->view("view_home", $data); } public function blog() { $data['title']="Somesite"; $this->load->view("view_blog", $data); } public function answers() {

Is chained assignment in C/C++ undefined behavior?

不打扰是莪最后的温柔 提交于 2019-12-04 06:21:12
Ignoring the types of variables, is expression like a=b=c has defined behavior in both C and C++? If so, can any one give me official evidence, like quotes from the standard, please? P.S. I searched the chained assignment but everything I got is associativity, but I didn't find any text about that in the C99 standard. Maybe I did it wrong? hoping anyone can help me. From the C++ Standard 5.17 Assignment and compound assignment operators [expr.ass] 1 The assignment operator (=) and the compound assignment operators all group right-to-left. All require a modifiable lvalue as their left operand

composite inheritance: how to assign a final field at sub-class constructor which depends on 'this' value (backward reference)?

时间秒杀一切 提交于 2019-12-04 05:31:47
问题 I use composite classes to group functionalities. But, the class A (with composite A1), got inherited by B (with composite B1), and a behavior existent at A1 is going to be adapted at B1, but the final a1 must be a B1 instance for this to work. Obs.: I have ways to make sure the composite instantiation happens properly (only by its composite partner). Unable to assign a B1 object to a1 final field: class finalFieldTestFails{ class A1{ A1(A a){} } class A{ protected final A1 a1; A(){ this.a1 =

C++ Beginner Infinite Loop When Input Wrong Data Type and Help Evaluate My Code

拥有回忆 提交于 2019-12-04 05:05:45
问题 I have an assignment to create a menu-based program to calculate area of several shapes using user-defined function. My code creates an infinite loop when a user input a char instead of a number. What should I do? Also, I would like if someone could evaluate my code, Is there anything I should change or modify? I'm still new to C++. Input: 1. a 2. j #include <iostream> #include <cmath> using namespace std; float Circle(double r1); float Rectangle(double length, double width); float Triangle

recursive function digits of a positive decimal integer in reverse order c++

天涯浪子 提交于 2019-12-04 04:54:06
问题 I have an assignment to write a recursive function that writes the digits of a positive integer in reverse order. My problem is that the function doesn't display the reverse correctly. I know im supposed to use % or 10 when displaying the number and / of 10 when in the recursive call as well as the base case is supposed to be < 10. Here is my code. #include <iostream> using namespace std; int reverse(int,int); int main() { int number; int n; cout << " Enter number to reverse." << endl; cin >>

C: transitive (double) assignments

对着背影说爱祢 提交于 2019-12-04 04:40:20
问题 I have used such construct in C: list->head = list->tail = NULL; and now I consider whether this really mean what I suppose. Is this mean? list->head = NULL; list->tail = NULL; or list->head = list->tail; list->tail = NULL; thx for clarifying 回答1: Neither of those is correct. Since the simple assignment = operator is right-to-left associative, your expression is identical to: list->head = (list->tail = NULL); NULL is assigned to tail, and then tail, which has the value of a null pointer, to