logic

Python Deleting Certain File Extensions

孤人 提交于 2019-11-30 10:01:29
I'm fairly new to Python, but I have gotten this code to work, and in fact, do what it's intended to do. However, I'm wondering if there is a more efficient way to code this, perhaps to enhance the processing speed. import os, glob def scandirs(path): for currentFile in glob.glob( os.path.join(path, '*') ): if os.path.isdir(currentFile): print 'got a directory: ' + currentFile scandirs(currentFile) print "processing file: " + currentFile png = "png"; jpg = "jpg"; if currentFile.endswith(png) or currentFile.endswith(jpg): os.remove(currentFile) scandirs('C:\Program Files (x86)\music\Songs')

MySQL GROUP_CONCAT with COLUMN SPLIT

ε祈祈猫儿з 提交于 2019-11-30 08:49:13
问题 I am working with a TABLE, need logical help. Check the below URL for the table structure and sample data. http://sqlfiddle.com/#!2/ece06/2 Table Schema: CREATE TABLE test ( ID INTEGER, NAME VARCHAR (50), VALUE INTEGER ); Inserted Data: INSERT INTO test VALUES (1, 'A', 4); INSERT INTO test VALUES (1, 'B', 5); INSERT INTO test VALUES (1, 'C', 8); INSERT INTO test VALUES (2, 'D', 9); INSERT INTO test VALUES (2, 'E', 9); INSERT INTO test VALUES (3, 'F', 9); INSERT INTO test VALUES (3, 'G', 9);

Ruby if .. elsIf .. else on a single line?

*爱你&永不变心* 提交于 2019-11-30 08:05:29
With the ruby ternary operator we can write the following logic for a simple if else construct: a = true ? 'a' : 'b' #=> "a" But what if I wanted to write this as if foo 'a' elsif bar 'b' else 'c' ? I could write it as the following, but it's a little difficult to follow: foo = true a = foo ? 'a' : (bar ? 'b' : 'c') #=> "a" foo = false bar = true a = foo ? 'a' : (bar ? 'b' : 'c') #=> "b" Are there any better options for handling such a scenario or is this our best bet if we wish to condense if..elsif..else logic into a single line? a = (foo && "a" or bar && "b" or "c") or a = ("a" if foo) || (

Any way to toggle between two strings using one piece of JavaScript?

假如想象 提交于 2019-11-30 08:03:41
问题 I want to do something like if(something.val() == 'string1') { something.val('string2'); } else if(something.val() == 'string2') { something.val('string1') } But in one line of code. I can't quite remember how it's done, but it involves question marks and colons... 回答1: Try: something.val(something.val() == 'string1' ? 'string2' : 'string1'); It is called a ternary expression. 回答2: Look ma, no ternary operator! The following works because Javascript short circuits boolean expressions. If

ReferenceError: Invalid left-hand side in assignment

落花浮王杯 提交于 2019-11-30 06:44:27
问题 my code for a rock paper scissors game (called toss) is as follows: var toss = function (one,two) { if(one = "rock" && two = "rock") { console.log("Tie! Try again!"); } // more similar conditions with `else if` }; When I enter in the parameters toss("rock","rock") I get this error code: "ReferenceError: Invalid left-hand side in assignment" How to fix it? What this error means and what other cases when this error can happen? 回答1: You have to use == to compare (or even === , if you want to

JavaScript library for logic programming [closed]

江枫思渺然 提交于 2019-11-30 06:42:06
Do you know of any good javascript library for logic programming? I'm interested in something like jsprolog , but I want to use javascript to communicate with the lib, and not a different language (such as prolog in this case). Many thanks. There are a bunch of other languages that compile to javascript: https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS It is possible (although not probable!) one of those has a javascript friendly API AND a suitable library that can by "compiled" into JavaScript. Exactly what you aren't looking for, and probably a time waster

Why does this if statement, with an assignment and equality check, evaluate to false?

大兔子大兔子 提交于 2019-11-30 05:33:13
How does a Java if statement work when it has an assignment and an equality check OR -d together?? public static void test() { boolean test1 = true; if (test1 = false || test1 == false) { System.out.println("TRUE"); } else { System.out.println("FALSE"); } } Why is this printing FALSE? The expression is not parsed the way you think. It's not (test1=false) || (test1 == false) in which case the result would have been true , but test1 = (false || test1 == false) The value of false || test1 == false expression is computed first, and it is false , because test1 is set to true going into the

Best resize and or crop logic

拈花ヽ惹草 提交于 2019-11-30 05:14:24
问题 I've come across this a few times and thought it would be good to put it out there. What's your best image resize and/or crop logic. The idea being that some method is called with a target image, dimensions and a crop flag - this would return or save off or whatever the desired image. Mine is below. Converted from VB to C# so yes there'll be small bugs but logic is what we're looking at. // INIT // On/off bool WeAreCropping = true; // Get some dimensions int TargetWidth = RequestedWidth; int

Relational operations using only increment, loop, assign, zero

守給你的承諾、 提交于 2019-11-30 05:14:08
问题 This is a follow up question for: Subtraction operation using only increment, loop, assign, zero We're only allowed to use the following operations: incr(x) - Once this function is called it will assign x + 1 to x assign(x, y) - This function will assign the value of y to x (x = y) zero(x) - This function will assign 0 to x (x = 0) loop X { } - operations written within brackets will be executed X times For example, addition can be implemented as follows: add(x, y) { loop x { y = incr(y) }

How do I find whether a number is positive, negative or zero without using if or for? [duplicate]

丶灬走出姿态 提交于 2019-11-30 04:48:25
问题 This question already has answers here : Checking whether a number is positive or negative using bitwise operators (15 answers) Closed 6 years ago . I want to implement the sign and zero flag setting in microprocessor. So I need to write a function to find whether the number is positive, negative or zero without using if or for loops and also only Boolean and bitwise operators are allowed . I did the following. But how to I implement it for zero condition ? int status (int x) { int sign = (x