qid
int64
1
74.7M
question
stringlengths
0
58.3k
date
stringlengths
10
10
metadata
list
response_j
stringlengths
2
48.3k
response_k
stringlengths
2
40.5k
2,402,433
As we use "default" keyword as a access specifier, and it can be used in switch statements as well with complete different purpose, So i was curious that is there any other keywords in java which can be used in more then one purposes
2010/03/08
[ "https://Stackoverflow.com/questions/2402433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/241717/" ]
Something no one else has mentioned yet: the **class** keyword has two different uses. Declaring a class: ``` class Test{}; ``` and indicating a class literal: ``` Class<Test> testClass = Test.class; ```
As all the other answers have stated, there are many keywords that server multiple purposes depending on context. I just wanted to add that there is a reason for this: There is a strong aversion to adding keywords because such additions break existing code, so when new features are added existing keywords are used if they make a reasonable fit, such as super and extends for generics and default for annotations, or they are just skipped as in the colon used in the enhanced for loop. So my point is to expect that as the language continues to evolve even more uses are found for existing keywords rather than introducing new ones.
2,402,433
As we use "default" keyword as a access specifier, and it can be used in switch statements as well with complete different purpose, So i was curious that is there any other keywords in java which can be used in more then one purposes
2010/03/08
[ "https://Stackoverflow.com/questions/2402433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/241717/" ]
The `default` keyword is not used as an access specifier. The absence of `private`, `protected` and `public` means use of `default`. Example: ``` class Test { // default access for class. int A; // default access for the class member. } ``` Some examples of Java keywords which find different use are: * `final` : A `final` `class` cannot be subclassed, a `final` method cannot be overridden, and a `final` variable can occur at most once as a left-hand expression. * `Super`: Used to access members of a class inherited by the class in which it appears, also used to forward a call from a constructor to a constructor in the superclass. * `Static`: Used to create `static` initialization blocks, also `static` members and `static` imports. * `for`:Used for the conventional `for` loop and the newer Java 1.5 `enhanced for` loop.
You can think of the following things 1. Default 2. final 3. super 4. "**:**" (colon) used at different places , which has a different meaning at different places
2,402,433
As we use "default" keyword as a access specifier, and it can be used in switch statements as well with complete different purpose, So i was curious that is there any other keywords in java which can be used in more then one purposes
2010/03/08
[ "https://Stackoverflow.com/questions/2402433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/241717/" ]
The `static` keyword associates methods and fields with a class instead of instances of that class, but it's also used to signify static initialization sections as in: ``` public class MyClass { private static int a; static { a = 1; } public static void doSomethingCool() { ... } } ``` Pascal's comment reminded me of static imports: ``` import static MyClass.doSomethingCool; public class MyOtherClass { public void foo() { // Use the static method from MyClass doSomethingCool(); } } ```
The "extends" keyword can be for single inheritance (either implementation or "pure abstract class" aka "interface inheritance" in Java). The "extends" keyword can also be used for multiple (interface) inheritance. The ones who always argue that Java doesn't support multiple inheritance will hence have a hard time arguing that "extends" in those two cases is doing exactly the same thing. Now I'm in the other camp: I consider that multiple interface inheritance is multiple inheritance and that implementation inheritance is just an OOP detail (that doesn't exist at the OOA/OOD level) and hence I consider that "extends" is really doing the same thing in both case and that hence my answer doesn't answer the question :) But it's an interesting keyword nonetheless :)
2,402,433
As we use "default" keyword as a access specifier, and it can be used in switch statements as well with complete different purpose, So i was curious that is there any other keywords in java which can be used in more then one purposes
2010/03/08
[ "https://Stackoverflow.com/questions/2402433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/241717/" ]
The "default" in the case of access modifier isn't a keyword - you don't write: `default void doSomething()` However, when specifying the default value of an attribute of annotations - it is. ``` switch (a) { default: something(); } ``` and ``` public @interface MyAnnotation { boolean bool() default true; } ``` That, together with `final` as pointed out by Jon Skeet seems to cover everything. Perhaps except the "overloaded" `for` keyword: `for (initializer; condition; step)` and `for (Type element : collection)`
*final* has different uses: * in a variable declaration it means a variable can't be changed. * In a method signature it means a method can't be overridden * In a parameter list it means a variable can't be altered in a method.
2,402,433
As we use "default" keyword as a access specifier, and it can be used in switch statements as well with complete different purpose, So i was curious that is there any other keywords in java which can be used in more then one purposes
2010/03/08
[ "https://Stackoverflow.com/questions/2402433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/241717/" ]
You can't use `default` as an access specifier, so I don't think even that counts. (EDIT: As Bozho pointed out, it can be used in annotations.) `final` means "can't be derived from / overridden" and "is read-only" which are two different - but related - meanings.
The `final` keyword can mean different things. * When modifying `classes` is means that the class cannot be subclassed. * When modifying a `method`, it means that the method cannot be Overridden. * When modifying a `variable`, it means that the variable cannot point to any other variable.
2,402,433
As we use "default" keyword as a access specifier, and it can be used in switch statements as well with complete different purpose, So i was curious that is there any other keywords in java which can be used in more then one purposes
2010/03/08
[ "https://Stackoverflow.com/questions/2402433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/241717/" ]
* **`default`** can be used both in a switch and as a default value in an annotation (as pointed out by Bozho) * **`final`** means "can't be derived from / overridden" and "is read-only" which are two different - but related - meanings (as pointed out by Jon) * **`extends`** can be used both to specify the supertype of a class and can be used in wildcards and type variables to put a constraint (related but not exactly the same) (`List<? extends Foo>`) * **`super`** can be used to specify to something in a superclass of the current class, or in a wildcard to put a constraint (`List<? super Foo>`) * **`static`** means both "part of the class, not an instance" (for methods, attributes or initializers) and as a `static import` * **`class`** to declare a class (`class Foo {}`), or to refer to a class literal (`Foo.class`) (as answered by ILMTitan) * (**`for`** can be used in a normal for loop and the "enhanced" for, but that's more like overloading (as Bozho puts it so nicely) than really having two meanings)
Something no one else has mentioned yet: the **class** keyword has two different uses. Declaring a class: ``` class Test{}; ``` and indicating a class literal: ``` Class<Test> testClass = Test.class; ```
2,402,433
As we use "default" keyword as a access specifier, and it can be used in switch statements as well with complete different purpose, So i was curious that is there any other keywords in java which can be used in more then one purposes
2010/03/08
[ "https://Stackoverflow.com/questions/2402433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/241717/" ]
* **`default`** can be used both in a switch and as a default value in an annotation (as pointed out by Bozho) * **`final`** means "can't be derived from / overridden" and "is read-only" which are two different - but related - meanings (as pointed out by Jon) * **`extends`** can be used both to specify the supertype of a class and can be used in wildcards and type variables to put a constraint (related but not exactly the same) (`List<? extends Foo>`) * **`super`** can be used to specify to something in a superclass of the current class, or in a wildcard to put a constraint (`List<? super Foo>`) * **`static`** means both "part of the class, not an instance" (for methods, attributes or initializers) and as a `static import` * **`class`** to declare a class (`class Foo {}`), or to refer to a class literal (`Foo.class`) (as answered by ILMTitan) * (**`for`** can be used in a normal for loop and the "enhanced" for, but that's more like overloading (as Bozho puts it so nicely) than really having two meanings)
*final* has different uses: * in a variable declaration it means a variable can't be changed. * In a method signature it means a method can't be overridden * In a parameter list it means a variable can't be altered in a method.
2,402,433
As we use "default" keyword as a access specifier, and it can be used in switch statements as well with complete different purpose, So i was curious that is there any other keywords in java which can be used in more then one purposes
2010/03/08
[ "https://Stackoverflow.com/questions/2402433", "https://Stackoverflow.com", "https://Stackoverflow.com/users/241717/" ]
The `static` keyword associates methods and fields with a class instead of instances of that class, but it's also used to signify static initialization sections as in: ``` public class MyClass { private static int a; static { a = 1; } public static void doSomethingCool() { ... } } ``` Pascal's comment reminded me of static imports: ``` import static MyClass.doSomethingCool; public class MyOtherClass { public void foo() { // Use the static method from MyClass doSomethingCool(); } } ```
As all the other answers have stated, there are many keywords that server multiple purposes depending on context. I just wanted to add that there is a reason for this: There is a strong aversion to adding keywords because such additions break existing code, so when new features are added existing keywords are used if they make a reasonable fit, such as super and extends for generics and default for annotations, or they are just skipped as in the colon used in the enhanced for loop. So my point is to expect that as the language continues to evolve even more uses are found for existing keywords rather than introducing new ones.
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
look for this in your standalone.xml socket-binding name="management-native" interface="management" port="9999" Source: <http://youtrack.jetbrains.com/issue/IDEA-77592>
Please make sute you had provided valid configuration file, may be your configuration file contains misplaced tag/element entries.
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
In my case, `standalone.xml` was corrupted (probably cause Idea froze and had to do hard shutdown). So I went to `standalone_xml_history` and copied `standalone.xml` from the day before. And it started to work normally again.
In my case: I typed 9990 in port offset of Run/Debug Configurations and it solved. :)
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
It seems that IntelliJ IDEA was not able to read offset value from "standalone.xml". to solve it, just set Port offset to 0 in Configuration window, it will manually add additional VM option: -Djboss.socket.binding.port-offset=0 [![enter image description here](https://i.stack.imgur.com/ahz2O.png)](https://i.stack.imgur.com/ahz2O.png)
I had the same problem, but have no idea what your setup looks like so the solution might not be the same. Also since your question is quite old you've probably figured out the answer by now. Anyways.. In case anyone else happens to stumble upon this issue, I solved it this way: We use Puppet in our project and I had changed a couple of `.yaml` files where I added some URLs. The URLs contained `&` which had to be `&amp;` and IntelliJ didn't notify me that this was the issue. It broke JBoss and everything. Try running JBoss `standalone.sh` in the terminal and see if you get a Stacktrace.
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
In my case, `standalone.xml` was corrupted (probably cause Idea froze and had to do hard shutdown). So I went to `standalone_xml_history` and copied `standalone.xml` from the day before. And it started to work normally again.
This is likely to be happening due to a parsing error in your configuration files. Start your JBoss/WildFly in the command line, so that you would see more details if this is happening because of a configuration (or parsing) error. * On Windows run `{JBOSS_HOME}/bin/standalone.bat` file so that it would open up a console window and try to start up your application server. * Look for any ERROR in the log and see if it is related to configuration. * For example: ERROR [org.jboss.as.server] WFLYSRV0055: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: WFLYCTL0085: Failed to parse configuration If this doesn't help, have a look at open the ports - maybe the port JBoss/WildFly is configured to is already used by some other application.
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
In my case, `standalone.xml` was corrupted (probably cause Idea froze and had to do hard shutdown). So I went to `standalone_xml_history` and copied `standalone.xml` from the day before. And it started to work normally again.
As shown below, adding the VM options to point to standalone config files fixed my issue ``` /Users/XXX/dev/apps/wildfly/wildfly-16.0.0.Final.XXX.2019.152-node1/standalone/configuration/ ```
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
Possible cause maybe an invalid configuration file "standalone.xml" or any other config file that you are using. I've put a tag at the wrong place and got the same error.
I had the same problem, but have no idea what your setup looks like so the solution might not be the same. Also since your question is quite old you've probably figured out the answer by now. Anyways.. In case anyone else happens to stumble upon this issue, I solved it this way: We use Puppet in our project and I had changed a couple of `.yaml` files where I added some URLs. The URLs contained `&` which had to be `&amp;` and IntelliJ didn't notify me that this was the issue. It broke JBoss and everything. Try running JBoss `standalone.sh` in the terminal and see if you get a Stacktrace.
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
In my case, `standalone.xml` was corrupted (probably cause Idea froze and had to do hard shutdown). So I went to `standalone_xml_history` and copied `standalone.xml` from the day before. And it started to work normally again.
I had the same error "Management Port Configuration not found" when i was trying to boot up my jboss. In my case i had accidentally deleted my standalone.xml. When i put it back all went fine. Another person had same issue turned out was some malformed tag in the standalone.xml.
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
It seems that IntelliJ IDEA was not able to read offset value from "standalone.xml". to solve it, just set Port offset to 0 in Configuration window, it will manually add additional VM option: -Djboss.socket.binding.port-offset=0 [![enter image description here](https://i.stack.imgur.com/ahz2O.png)](https://i.stack.imgur.com/ahz2O.png)
In my case: I typed 9990 in port offset of Run/Debug Configurations and it solved. :)
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
look for this in your standalone.xml socket-binding name="management-native" interface="management" port="9999" Source: <http://youtrack.jetbrains.com/issue/IDEA-77592>
This is likely to be happening due to a parsing error in your configuration files. Start your JBoss/WildFly in the command line, so that you would see more details if this is happening because of a configuration (or parsing) error. * On Windows run `{JBOSS_HOME}/bin/standalone.bat` file so that it would open up a console window and try to start up your application server. * Look for any ERROR in the log and see if it is related to configuration. * For example: ERROR [org.jboss.as.server] WFLYSRV0055: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: WFLYCTL0085: Failed to parse configuration If this doesn't help, have a look at open the ports - maybe the port JBoss/WildFly is configured to is already used by some other application.
22,729,795
i has a layout: ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="4dp" android:paddingTop="4dp" > <LinearLayout android:id="@+id/lineradapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp" android:layout_marginTop="4dp" android:layout_marginLeft="6dp" android:layout_marginRight="6dp"> <FrameLayout android:id="@+id/frameLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="6dp"> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#525252" android:textSize="16sp" android:textStyle="normal" /> <TextView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:fontFamily="normal" android:paddingBottom="2dip" android:paddingTop="6dip" android:text="00:00" android:textColor="#999999" android:textSize="14sp" android:textStyle="italic" /> </FrameLayout> <TextView android:id="@+id/desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingBottom="6dip" android:textColor="#acacac" android:textSize="16dp" /> <View android:layout_width="fill_parent" android:layout_height="1dp" android:background="#e7e7e7" android:paddingTop="6dp" android:paddingBottom="4dp" /> </LinearLayout> </RelativeLayout> ``` in this layout i want to position the ListView. At the end, so that you can first see what the top, and then scroll down to see ListView. How to do it? I probyval added before /RelativeLayout> ``` <LinearLayout android:id="@+id/comentadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="5dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="10dp"> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="4dp" android:layout_gravity="top|center"/> <ListView android:id="@+id/commentList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> ``` But it is still located at the top.
2014/03/29
[ "https://Stackoverflow.com/questions/22729795", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3158925/" ]
Your standalone xml may be malformed in some way. Check to see if you have special characters that you will have to escape or extra closing or opening tags etc.
In my case, `standalone.xml` was corrupted (probably cause Idea froze and had to do hard shutdown). So I went to `standalone_xml_history` and copied `standalone.xml` from the day before. And it started to work normally again.
4,377,066
Let's consider the Coulomb Hamiltonian $$ -\Delta - \frac{1}{|x|}$$ in $\mathbb{R}^3$. It is known that eigenvalues of the Coulomb Hamiltonian are negative. I know it has negative eigenvalues, but I can't prove it hasn't nonnegative eigenvalues. That is, I want to prove the following. If smooth function $u$ satisfies the following $$\int\_{\mathbb{R}^3 } |u(x)|^2 dx + \int\_{\mathbb{R}^3 } |\nabla u(x)|^2 dx < \infty$$ and $$-\Delta u - \frac{u}{|x|} = \lambda u$$ for some $\lambda \geq 0$, then $u=0$. Any advice would be appreciated.
2022/02/08
[ "https://math.stackexchange.com/questions/4377066", "https://math.stackexchange.com", "https://math.stackexchange.com/users/1017662/" ]
Let $V(x) = -\frac{1}{|x|}$ be the potential and $H = -\Delta + V$. We know that $H$ is a self-adjoint operator on $H^2(\mathbb{R}^3)$. Let $U(t)\psi(x) = e^{-\frac{3t}{2}}\psi(e^{-t}x)$. $U$ is a strongly continuous unitary group (dilation). Now let $\lambda$ be an eigenvalue of $H$. Since $H$ is self-adjoint and $U$ a unitary group, we have $\lambda \in \mathbb{R}$ and we observe that $\langle \psi, [U(t),H] \psi \rangle = \langle U(-t)\psi, H \psi \rangle + \langle H\psi, U(t)\psi \rangle = \langle U(-t)\psi, \lambda \psi \rangle + \langle \lambda\psi, U(t)\psi \rangle= 0$ Observe that the potential $V$ satisfies $U(-t)VU(t) = e^{-t}V$. So, $ 0 = \lim\_{t \to 0} \langle \psi, \frac{1}{t}[U(t),H] \psi \rangle = \lim\_{t \to 0} \langle U(-t)\psi, \frac{1}{t}(H - U(-t)HU(t)) \psi \rangle = \lim\_{t \to 0} \langle \psi, \frac{1-e^{-2t}}{t} (-\Delta \psi)\rangle + \langle \psi, \frac{1-e^{-t}}{t} V\psi \rangle = \langle \psi, (-2\Delta + V) \psi \rangle = \langle \psi, -\Delta \psi + H\psi \rangle = \langle \psi, -\Delta \psi + \lambda\psi \rangle$ The calculation shows that, if $||\psi|| = 1$: $-\lambda = \langle \psi, -\Delta \psi \rangle > 0$. So, the point spectrum is contained in $(-\infty, 0 )$.
As I recall, there's a theorem that bound states with potentials that go to zero at infinity necessarily have negative total energy, otherwise the wave function is not normalizable. This implies eigenvalues of the energy will be non-positive. The remaining question is whether the ground state has 0 energy. Waves in a bounded region of space give rise to interference which tends to limit solutions to the associated wave equation, so bound states imply discrete Eigenvalues. Now a Coulomb potential has scattering states, i.e. unbounded: [Coulomb Scattering](https://en.wikipedia.org/wiki/Coulomb_scattering_state#:%7E:text=A%20Coulomb%20scattering%20state%20in,a%20finite%20region%20of%20space.). These have a continuous spectrum of positive eigenvalues.
1,279,443
> > Solve $$ 3-\frac{4}{9^x}-\frac{4}{81^x}=0 $$ > > > I had this question for an exam today and I want to find out if my answer was correct.
2015/05/12
[ "https://math.stackexchange.com/questions/1279443", "https://math.stackexchange.com", "https://math.stackexchange.com/users/112498/" ]
Substitute $t = 2 / 9^x$, then you get simple quadratic: $t^2 + 2t - 3 = 0$ ... **UPDATE:** I want to update my answer regarding the solution of the equation: The question does not specify if only real solutions are required. If that is the case there is a single solution: $ \ln2 / \ln9 $. However, this is not the only solution as the quadratic has one more root (-3) which will result in complex (infinitely many) solutions, i.e.: $$ 9^x = - \frac 2 3 $$ or $$ x = \frac{ln (-1) + ln(2/3)}{ln9} $$ $ ln(-1)=(2k+1)\pi i$ for $ k \in \mathbb{Z} $, which give us infinitely many solutions to the equation: $$ x=\frac{ln(2/3)}{ln9} + i \frac{(2k+1) \pi}{ln9} $$
So if we let the common denominator be $81^x$, we would get this: $$\frac{81^x\times 3 - 4\times9^x - 4}{81^x} = 0$$ Use the quadratic formula on the numerator while letting $y = 9^x$, and we get $$y = 9^x = \frac{2\pm 4}{3}$$ So $$x = \frac{\ln 2}{\ln 9}$$ since $\ln \frac{-2}{3}$ does not exist.
7,050,584
Hi this may be a silly question, but I can't find the answer anywhere. I'm writing a chrome extension, all I need is to read in the html of the current page so I can extract some data from it. here's what I have so far: ``` <script> window.addEventListener("load", windowLoaded, false); function windowLoaded() { alert(document.innerHTML) }); } </script> ``` Can anybody tell me what I'm doing wrong? thanks,
2011/08/13
[ "https://Stackoverflow.com/questions/7050584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/892545/" ]
``` function windowLoaded() { alert('<html>' + document.documentElement.innerHTML + '</html>'); } addEventListener("load", windowLoaded, false); ``` ~~Notice how `windowLoaded` is created before it is used, not after, which won't work.~~ Also notice how I am getting the innerHTML of `document.documentElement`, which is the `html` tag, then adding the `html` source tags around it.
``` window.addEventListener("load", windowLoaded, false); function windowLoaded() { alert(document.documentElement.innerHTML); } ``` You had a `}` with no purpose, and the `});` should just be `}`. These are syntax errors. Also, it's `document.documentElement.innerHTML`, since it's not a property of `document`.
7,050,584
Hi this may be a silly question, but I can't find the answer anywhere. I'm writing a chrome extension, all I need is to read in the html of the current page so I can extract some data from it. here's what I have so far: ``` <script> window.addEventListener("load", windowLoaded, false); function windowLoaded() { alert(document.innerHTML) }); } </script> ``` Can anybody tell me what I'm doing wrong? thanks,
2011/08/13
[ "https://Stackoverflow.com/questions/7050584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/892545/" ]
> > I'm writing a chrome extension, all I need is to read in the html of > the current page so **I can extract some data** from it. > > > I think an important answer here is not the correct code to use to alert the `innerHTML` but **how to get the data you need from what's already been rendered**. As [pimvdb](https://stackoverflow.com/questions/7050584/chrome-extension-read-innerhtml-of-the-current-page/7050927#7050634) pointed out, your code isn't working because of a typo and needing `document.documentElement.innerHTML`, something you can diagnose in the Chrome console (Ctrl+Shift+I). But that's secondary to *why* you'd want the inner HTML in the first place. Whether you're looking for a certain node, specific text, how many `<div>` elements exist, the value of an ID, etc., I'd heavily recommend the use of a library like [jQuery](http://jquery.com/) (vanilla JS works, but it can be verbose and unwieldy). Instead of reading in all the HTML and parsing it with string functions or regex, you probably want to take advantage of all the DOM parsing functionality already available to you. In other words, something like this: ``` $("#some_id").val(); // jQuery document.getElementById("some_id").value; // vanilla JS ``` is probably way safer, easier and more readable than something eminently breakable like this (probably a bit off here, but just to make a point): ``` innerHTML.match(/<[^>]+id="some_id"[^>]+value="(.*?)"[^>]*?>/i)[1]; ```
``` window.addEventListener("load", windowLoaded, false); function windowLoaded() { alert(document.documentElement.innerHTML); } ``` You had a `}` with no purpose, and the `});` should just be `}`. These are syntax errors. Also, it's `document.documentElement.innerHTML`, since it's not a property of `document`.
7,050,584
Hi this may be a silly question, but I can't find the answer anywhere. I'm writing a chrome extension, all I need is to read in the html of the current page so I can extract some data from it. here's what I have so far: ``` <script> window.addEventListener("load", windowLoaded, false); function windowLoaded() { alert(document.innerHTML) }); } </script> ``` Can anybody tell me what I'm doing wrong? thanks,
2011/08/13
[ "https://Stackoverflow.com/questions/7050584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/892545/" ]
``` function windowLoaded() { alert('<html>' + document.documentElement.innerHTML + '</html>'); } addEventListener("load", windowLoaded, false); ``` ~~Notice how `windowLoaded` is created before it is used, not after, which won't work.~~ Also notice how I am getting the innerHTML of `document.documentElement`, which is the `html` tag, then adding the `html` source tags around it.
Use `document.documentElement.outerHTML`. (Note that this is not supported in Firefox; irrelevant in your case.) However, this is still not perfect as it doesn't return nodes outside the root element (`!doctype` and possibly some comments or processing instructions). The `document.innerHTML` property is, AFAIK, specified in HTML5 specification, but currently not supported in any browser. Just FYI, navigating to `view-source:www.example.com` also displays the entire markup (Chrome & Firefox). But I don't know whether you can work with it somehow.
7,050,584
Hi this may be a silly question, but I can't find the answer anywhere. I'm writing a chrome extension, all I need is to read in the html of the current page so I can extract some data from it. here's what I have so far: ``` <script> window.addEventListener("load", windowLoaded, false); function windowLoaded() { alert(document.innerHTML) }); } </script> ``` Can anybody tell me what I'm doing wrong? thanks,
2011/08/13
[ "https://Stackoverflow.com/questions/7050584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/892545/" ]
``` function windowLoaded() { alert('<html>' + document.documentElement.innerHTML + '</html>'); } addEventListener("load", windowLoaded, false); ``` ~~Notice how `windowLoaded` is created before it is used, not after, which won't work.~~ Also notice how I am getting the innerHTML of `document.documentElement`, which is the `html` tag, then adding the `html` source tags around it.
> > I'm writing a chrome extension, all I need is to read in the html of > the current page so **I can extract some data** from it. > > > I think an important answer here is not the correct code to use to alert the `innerHTML` but **how to get the data you need from what's already been rendered**. As [pimvdb](https://stackoverflow.com/questions/7050584/chrome-extension-read-innerhtml-of-the-current-page/7050927#7050634) pointed out, your code isn't working because of a typo and needing `document.documentElement.innerHTML`, something you can diagnose in the Chrome console (Ctrl+Shift+I). But that's secondary to *why* you'd want the inner HTML in the first place. Whether you're looking for a certain node, specific text, how many `<div>` elements exist, the value of an ID, etc., I'd heavily recommend the use of a library like [jQuery](http://jquery.com/) (vanilla JS works, but it can be verbose and unwieldy). Instead of reading in all the HTML and parsing it with string functions or regex, you probably want to take advantage of all the DOM parsing functionality already available to you. In other words, something like this: ``` $("#some_id").val(); // jQuery document.getElementById("some_id").value; // vanilla JS ``` is probably way safer, easier and more readable than something eminently breakable like this (probably a bit off here, but just to make a point): ``` innerHTML.match(/<[^>]+id="some_id"[^>]+value="(.*?)"[^>]*?>/i)[1]; ```
7,050,584
Hi this may be a silly question, but I can't find the answer anywhere. I'm writing a chrome extension, all I need is to read in the html of the current page so I can extract some data from it. here's what I have so far: ``` <script> window.addEventListener("load", windowLoaded, false); function windowLoaded() { alert(document.innerHTML) }); } </script> ``` Can anybody tell me what I'm doing wrong? thanks,
2011/08/13
[ "https://Stackoverflow.com/questions/7050584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/892545/" ]
> > I'm writing a chrome extension, all I need is to read in the html of > the current page so **I can extract some data** from it. > > > I think an important answer here is not the correct code to use to alert the `innerHTML` but **how to get the data you need from what's already been rendered**. As [pimvdb](https://stackoverflow.com/questions/7050584/chrome-extension-read-innerhtml-of-the-current-page/7050927#7050634) pointed out, your code isn't working because of a typo and needing `document.documentElement.innerHTML`, something you can diagnose in the Chrome console (Ctrl+Shift+I). But that's secondary to *why* you'd want the inner HTML in the first place. Whether you're looking for a certain node, specific text, how many `<div>` elements exist, the value of an ID, etc., I'd heavily recommend the use of a library like [jQuery](http://jquery.com/) (vanilla JS works, but it can be verbose and unwieldy). Instead of reading in all the HTML and parsing it with string functions or regex, you probably want to take advantage of all the DOM parsing functionality already available to you. In other words, something like this: ``` $("#some_id").val(); // jQuery document.getElementById("some_id").value; // vanilla JS ``` is probably way safer, easier and more readable than something eminently breakable like this (probably a bit off here, but just to make a point): ``` innerHTML.match(/<[^>]+id="some_id"[^>]+value="(.*?)"[^>]*?>/i)[1]; ```
Use `document.documentElement.outerHTML`. (Note that this is not supported in Firefox; irrelevant in your case.) However, this is still not perfect as it doesn't return nodes outside the root element (`!doctype` and possibly some comments or processing instructions). The `document.innerHTML` property is, AFAIK, specified in HTML5 specification, but currently not supported in any browser. Just FYI, navigating to `view-source:www.example.com` also displays the entire markup (Chrome & Firefox). But I don't know whether you can work with it somehow.
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
My two cents to the above answers.. I see most of the answers has mentioned only about the hostnames but no port. If we haven't specified ports, then server will dynamically assign RMI port. There wont be any issues, if both the servers are in same subnet or no firewall issues. If there is any concerns, we can add below JVM parameter to freeze. ``` -Dcom.sun.management.jmxremote.rmi.port ``` Ex: ``` <option name="-Dcom.sun.management.jmxremote.rmi.port" value="11001"/> ``` Make sure both RMI and JMX ports should be the same. For more, [click here](https://docs.oracle.com/javase/9/management/monitoring-and-management-using-jmx-technology.htm#JSMGM-GUID-F08985BB-629A-4FBF-A0CB-8762DF7590E0)
The following worked for me, thanks to @Arpit Agarwal. Added this additional jvm parameter which worked for me. ``` -Djava.rmi.server.hostname=192.168.1.16 ``` Complete list which worked for me. ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=21845 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.1.16 -Dcom.sun.management.jmxremote.rmi.port=10099 ```
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
My two cents to the above answers.. I see most of the answers has mentioned only about the hostnames but no port. If we haven't specified ports, then server will dynamically assign RMI port. There wont be any issues, if both the servers are in same subnet or no firewall issues. If there is any concerns, we can add below JVM parameter to freeze. ``` -Dcom.sun.management.jmxremote.rmi.port ``` Ex: ``` <option name="-Dcom.sun.management.jmxremote.rmi.port" value="11001"/> ``` Make sure both RMI and JMX ports should be the same. For more, [click here](https://docs.oracle.com/javase/9/management/monitoring-and-management-using-jmx-technology.htm#JSMGM-GUID-F08985BB-629A-4FBF-A0CB-8762DF7590E0)
look in /etc/hosts if you don't have a wrong IP for your machine example : 127.0.0.1 localhost 127.0.0.2 your\_machine 185.12.58.2 your\_machine (the good IP for your machine) JMX take the IP 127.0.0.2 and forget the other
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
I experienced the problem where it said 'Adding ' forever and didn't seem to be able to connect. I got passed the problem by changing the jvisualvm proxy settings (Tools->options->network). Once I changed the option to No Proxy, I was able to connect. My jvm was started with the following options: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=2222 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=<external_IP_of_server> ``` Then when I added the jmx connection, I specified "external\_IP\_of\_server:2222"
If you run `jar` file (via -jar option), you must specifie all other jvm options before `-jar` option!
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
I experienced the problem where it said 'Adding ' forever and didn't seem to be able to connect. I got passed the problem by changing the jvisualvm proxy settings (Tools->options->network). Once I changed the option to No Proxy, I was able to connect. My jvm was started with the following options: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=2222 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=<external_IP_of_server> ``` Then when I added the jmx connection, I specified "external\_IP\_of\_server:2222"
The following worked for me, thanks to @Arpit Agarwal. Added this additional jvm parameter which worked for me. ``` -Djava.rmi.server.hostname=192.168.1.16 ``` Complete list which worked for me. ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=21845 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.1.16 -Dcom.sun.management.jmxremote.rmi.port=10099 ```
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
In addition to listening to the port you specified (1100) the JMX server also listens to a randomly chosen (ephemeral) port. Check, e.g. with `lsof -i|grep java` if you are on linux/osx, which ports the java process listens to and make sure your firewall is open for the ephemeral port as well.
The following worked for me, thanks to @Arpit Agarwal. Added this additional jvm parameter which worked for me. ``` -Djava.rmi.server.hostname=192.168.1.16 ``` Complete list which worked for me. ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=21845 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.1.16 -Dcom.sun.management.jmxremote.rmi.port=10099 ```
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
If you run `jar` file (via -jar option), you must specifie all other jvm options before `-jar` option!
The following worked for me, thanks to @Arpit Agarwal. Added this additional jvm parameter which worked for me. ``` -Djava.rmi.server.hostname=192.168.1.16 ``` Complete list which worked for me. ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=21845 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.1.16 -Dcom.sun.management.jmxremote.rmi.port=10099 ```
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
Add `-Djava.rmi.server.hostname = host ip`. Even i faced the same problem and this did the trick. Addition of this `-Djava.rmi.server.hostname = host ip` forces RMI service to use the host ip instead of 127.0.0.1
look in /etc/hosts if you don't have a wrong IP for your machine example : 127.0.0.1 localhost 127.0.0.2 your\_machine 185.12.58.2 your\_machine (the good IP for your machine) JMX take the IP 127.0.0.2 and forget the other
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
These are the steps that worked for me (Debian behind firewall on the server side was reached over VPN from my local Mac): 1. Check server public ip `ifconfig` 2. Use JVM params: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=[jmx port] -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=[server ip from step 1] ``` 3. Run application 4. Find process ID of the running java process 5. Check all ports used by JMX/RMI `netstat -lp | grep [pid from step 4]` 6. Open all ports from step 5 on the firewall Voila.
If you run `jar` file (via -jar option), you must specifie all other jvm options before `-jar` option!
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
I had a similar issue when using port forwarding. I have a remote machine with Tomcat listening for JMX interactions on `localhost:9000`. From my local machine, I'm used to do port-forwarding with: ``` ssh -L 9001:localhost:9000 tomcat.example.com ``` (so remote port 9000 is forwarded to my local machine's port 9001). Then when I tried to use VisualVM to connect to `localhost:9001`, the connection was refused. JMX seems to require port numbers on both sides to be identical. So my solution was using port numbers 9000 and 9000: ``` ssh -L 9000:localhost:9000 tomcat.example.com ``` Now my local machine's VisualVM connects successfully to the remote machine's Tomcat via `localhost:9000`. Make sure that you don't have any other service (Tomcat on dev machine?) listening on the same port. Also take a look at [setting up parameters correctly](https://stackoverflow.com/a/32418821/923560).
look in /etc/hosts if you don't have a wrong IP for your machine example : 127.0.0.1 localhost 127.0.0.2 your\_machine 185.12.58.2 your\_machine (the good IP for your machine) JMX take the IP 127.0.0.2 and forget the other
11,628,595
For some weird reason I am not able to connect using `VisualVM` or `jconsole` to a JMX. The parameters used to start the VM to be monitored: ``` -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=1100 ``` I checked, and I can telnet to this port, from both locally and remotely. Still, VisualVM or jconsole are failing to connect, after spending some considerably time trying to. ``` REMOTE MACHINE with JMX (debian) java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode) MY WORKSTATION (OS X) java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode) ``` What is the problem?
2012/07/24
[ "https://Stackoverflow.com/questions/11628595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/99834/" ]
My two cents to the above answers.. I see most of the answers has mentioned only about the hostnames but no port. If we haven't specified ports, then server will dynamically assign RMI port. There wont be any issues, if both the servers are in same subnet or no firewall issues. If there is any concerns, we can add below JVM parameter to freeze. ``` -Dcom.sun.management.jmxremote.rmi.port ``` Ex: ``` <option name="-Dcom.sun.management.jmxremote.rmi.port" value="11001"/> ``` Make sure both RMI and JMX ports should be the same. For more, [click here](https://docs.oracle.com/javase/9/management/monitoring-and-management-using-jmx-technology.htm#JSMGM-GUID-F08985BB-629A-4FBF-A0CB-8762DF7590E0)
I found the problem, my rmi service was running on the host ip which was "127.0.0.1". To connect remotely to the jvm I had to bind the external ip to the hostname. To do this in unix systems use command `hostname` to get the name of the hostname. Then check the ip that is assigned to the hostname, to find out this use `ping $(hostname)` you will see that system is pinging the hosname's ip. If your host ip was the default "127.0.0.1" and you wanted to change it, just edit the file /etc/hosts as superuser. After rebooting the rmi service, you can reach it from the remote machine.
10,336,550
I'm in the process of trying to understand recursion better, so I decided to write a program to determine the shortest paths to all fields on an N \* N game board, using recursion (I know BFS would be faster here, this is just for the sake of learning): ``` void visit(int x, int y, int moves) { if (x < 0 || x >= n || y < 0 || y >= n) { return; // out of board } else if (board[y][x] != -1) { // already visited, check if path is shorter if (moves < board[y][x]) board[y][x] = moves; return; } else { // first time visiting board[y][x] = moves; visit(x + 1, y, moves + 1); // right visit(x, y + 1, moves + 1); // down visit(x, y - 1, moves + 1); // up visit(x - 1, y, moves + 1); // left } } # called with visit(0, 0, 0), so it should be able to start at any field ``` However, for a 3x3 board, it yields the following board: ``` 0 1 2 1 2 3 6 5 4 ``` The first two rows are right, however, the last row (except the last column in the last row) is wrong. It should be: ``` 0 1 2 1 2 3 2 3 4 ``` Here's a 4x4 board: ``` 0 1 2 3 1 2 3 4 12 9 6 5 13 8 7 6 ```
2012/04/26
[ "https://Stackoverflow.com/questions/10336550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1359067/" ]
``` else if (board[y][x] != -1) { // already visited, check if path is shorter if (moves &lt; board[y][x]) board[y][x] = moves; return; } ``` Returning here is wrong. You've just lowered the score on this path—there are probably other paths in the area whose scores could be lowered: ``` void visit(int x, int y, int moves) { if (x < 0 || x >= n || y < 0 || y >= n) { return; // out of board } else if (board[y][x] == -1 || moves < board[y][x]) { // first time visiting board[y][x] = moves; visit(x + 1, y, moves + 1); visit(x, y + 1, moves + 1); visit(x, y - 1, moves + 1); visit(x - 1, y, moves + 1); } else { return; } } ``` Works as expected.
You are doing a depth first search which may find sub-optimal paths to some squares. To get optimal paths, if your path is shorter you should still visit from it, even if it is already visited.
10,336,550
I'm in the process of trying to understand recursion better, so I decided to write a program to determine the shortest paths to all fields on an N \* N game board, using recursion (I know BFS would be faster here, this is just for the sake of learning): ``` void visit(int x, int y, int moves) { if (x < 0 || x >= n || y < 0 || y >= n) { return; // out of board } else if (board[y][x] != -1) { // already visited, check if path is shorter if (moves < board[y][x]) board[y][x] = moves; return; } else { // first time visiting board[y][x] = moves; visit(x + 1, y, moves + 1); // right visit(x, y + 1, moves + 1); // down visit(x, y - 1, moves + 1); // up visit(x - 1, y, moves + 1); // left } } # called with visit(0, 0, 0), so it should be able to start at any field ``` However, for a 3x3 board, it yields the following board: ``` 0 1 2 1 2 3 6 5 4 ``` The first two rows are right, however, the last row (except the last column in the last row) is wrong. It should be: ``` 0 1 2 1 2 3 2 3 4 ``` Here's a 4x4 board: ``` 0 1 2 3 1 2 3 4 12 9 6 5 13 8 7 6 ```
2012/04/26
[ "https://Stackoverflow.com/questions/10336550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1359067/" ]
``` else if (board[y][x] != -1) { // already visited, check if path is shorter if (moves &lt; board[y][x]) board[y][x] = moves; return; } ``` Returning here is wrong. You've just lowered the score on this path—there are probably other paths in the area whose scores could be lowered: ``` void visit(int x, int y, int moves) { if (x < 0 || x >= n || y < 0 || y >= n) { return; // out of board } else if (board[y][x] == -1 || moves < board[y][x]) { // first time visiting board[y][x] = moves; visit(x + 1, y, moves + 1); visit(x, y + 1, moves + 1); visit(x, y - 1, moves + 1); visit(x - 1, y, moves + 1); } else { return; } } ``` Works as expected.
This would work. ``` void visit(int x, int y, int moves) { if (x < 0 || x >= n || y < 0 || y >= n) { return; // out of board } else if ( board[y][x] == -1 || moves < board[y][x]) { board[y][x] = moves; visit(x + 1, y, moves + 1); visit(x, y + 1, moves + 1); visit(x, y - 1, moves + 1); visit(x - 1, y, moves + 1); } } ``` Moreover, if you initialize each element of board with (2\*n-2) instead of -1, you can drop the ( board[y][x] == -1 ) condition and have just (moves < board[y][x]) in the else if part.
23,282,280
For the following code, ``` class A { private: virtual void f() = 0; virtual void g() = 0; ... public: A() { } ... } class B : public A { private: void f() { ... } void g() { ... } void h() { if (...) { f(); } else { g(); } } ... public: B() { h(); } ... } class C : public A { private: void f() { ... } void g() { f(); } void h() { if (...) { f(); } else { g(); } } ... public: C() { h(); } ... } ``` is there a way to avoid repetition of h() (the context of function h() in both classes B and C is the same) or we cannot avoid it simply because we cannot call pure virtual functions in constructors?
2014/04/25
[ "https://Stackoverflow.com/questions/23282280", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1069252/" ]
You can implement your function `h()` as a member of `A`. The pure virtual function call would only be an issue if `h()` gets executed during the body of `A::A()` (or other `A` constructors or `A::~A()`). Inside the body of `B::B()` or `C::C()`, the polymorphic type of `*this` is `B` or `C` respectively, so your virtual overrides declared in class `B` or `C` will have effect.
Sure, add an intermediate class D which only implements that function and inherits from A. Then B and C can inherit from D.
25,415,146
Adding a `mailto:` link on my site, but it occurred to me that it's possible the user may not have a client set up to handle it I found [this](https://stackoverflow.com/questions/7591474/has-anyone-ever-come-up-with-a-way-to-detect-the-email-program-a-recipient-is-us) thread from 3 years ago and was hoping there's something doable now. I don't necessarily need to figure out what's handling their mailto links, but rather if it got handled at all. Is this possible?
2014/08/20
[ "https://Stackoverflow.com/questions/25415146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/266542/" ]
No. =( The answer in your link still stands today. The knowledge that something was even capable of handling the event is way to much information to give to a browser.
No, `mailto:` is very limited, the information is beyond the scope of the browser
25,415,146
Adding a `mailto:` link on my site, but it occurred to me that it's possible the user may not have a client set up to handle it I found [this](https://stackoverflow.com/questions/7591474/has-anyone-ever-come-up-with-a-way-to-detect-the-email-program-a-recipient-is-us) thread from 3 years ago and was hoping there's something doable now. I don't necessarily need to figure out what's handling their mailto links, but rather if it got handled at all. Is this possible?
2014/08/20
[ "https://Stackoverflow.com/questions/25415146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/266542/" ]
No. =( The answer in your link still stands today. The knowledge that something was even capable of handling the event is way to much information to give to a browser.
The answer is no. However, you can get a free account with jotform.com and use that. It works GREAT. Hopefully this can help.
25,415,146
Adding a `mailto:` link on my site, but it occurred to me that it's possible the user may not have a client set up to handle it I found [this](https://stackoverflow.com/questions/7591474/has-anyone-ever-come-up-with-a-way-to-detect-the-email-program-a-recipient-is-us) thread from 3 years ago and was hoping there's something doable now. I don't necessarily need to figure out what's handling their mailto links, but rather if it got handled at all. Is this possible?
2014/08/20
[ "https://Stackoverflow.com/questions/25415146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/266542/" ]
No, `mailto:` is very limited, the information is beyond the scope of the browser
The answer is no. However, you can get a free account with jotform.com and use that. It works GREAT. Hopefully this can help.
245,272
Dr. Lapham speaks to Malorie: > > Dr. Lapham: But if that's not what you want, **there are plenty of > couples who are desperate to adopt a child**. There are no judgments > here. You can make whatever choice you want. > > > Why did Dr Lapham suggest that Malorie put her child up for adoption?
2021/03/31
[ "https://scifi.stackexchange.com/questions/245272", "https://scifi.stackexchange.com", "https://scifi.stackexchange.com/users/139481/" ]
In the [original script](https://www.scriptslug.com/assets/uploads/scripts/bird-box-2018.pdf), it was Malorie that was considering putting her child up for adoption. She's suffering from anxiety and is in a state of denial about the pregnancy. She sees an adoption leaflet and takes it from the doctor's office. In the film they seem to have combined the two scenes to cut down on running time. > > **DR. LAPHAM:** *You’re due in twelve weeks, so let’s try some natural remedies for the insomnia before I prescribe anything. > (casually) **You have a name picked?*** > > > **MALORIE:** ***Not yet. Something about it... It hasn’t really clicked with me. You know? The idea. Motherhood.*** > > > **DR. LAPHAM:** *That’s normal. It will pass.* > > > Malorie smiles sadly and nods. While holding that smile: > > > **MALORIE:** *What if it doesn’t?* > > > Dr. Lapham reads from her clipboard. > > > **DR. LAPHAM:** *Everything will change after the baby’s born. Now, let’s talk about > the next trimester. Expect more weight gain, but if it gets more than forty pounds over where you were before, call me.* > > > CREEPING IN on Malorie as she listens to the doctor, and **it all plays out on her face: A silent war against encroaching anxiety.** She looks away. Takes a breath as Lapham continues: > > > **DR. LAPHAM** (O.S.) (CONT’D): *Heartburn will be more common. You might also deal with hemorrhoids, discharge, bleeding, and varicose veins, that’s all natural. Be aware > of Braxton Hicks contractions at odd hours, like tremors before a real quake...* > > > The doctor’s voice grows more and more distant as Malorie struggles to keep it all together. And then-- > > > INT. HOSPITAL BATHROOM - MOMENTS LATER > Malorie vomits into the toilet bowl. > > She cleans herself up at the sink and stares at herself in the mirror. Her own bloodshot eyes stare back. > > Malorie washes her face. Then goes to the towels to dry her > face and hands. > > **Nearby: A basket of reading material. Magazines. Pamphlets.** > > **Flyers about parenthood, childbirth.** > > **Malorie notices one. Picks it up.** > > **The headline: “YOU HAVE A CHOICE. // Give your child to a good home!”** > > An informational flyer on adoption. > > Malorie considers something. > > Then puts the flyer in her purse. > > >
In the United States, [there are more couples looking to adopt an infant than there are infants](https://adoptionnetwork.com/adoption-myths-facts/domestic-us-statistics/) (the statistics change as a child gets older). Therefore, when faced with someone expecting a child who isn't certain that they want to raise them for whatever reason, a medical professional will often suggest adoption so that the baby is available to those parents. In Malorie's case, she is not in a dedicated relationship, and therefore she faces additional difficulties in raising a child. I don't remember if she'd expressed ambivalence regarding that, but either way, most medical professionals want their patients to know all of their options should their decision change so that they don't feel trapped in their decision.
35,764,231
I am implementing custom list view in alert dialog. It's not showing up any view. I have created one query to get the list of titles from table. I want to show this list in alert dialog. What's going wrong? alert dialog : ``` selectTable.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int selected = 0; TimeTableHelper th = new TimeTableHelper(getApplicationContext()); final List<String> tables = new ArrayList<String>(th.getTitle()); AlertDialog.Builder alertDialog = new AlertDialog.Builder(AddEventActivity.this); LayoutInflater inflater = getLayoutInflater(); View convertView = (View) inflater.inflate(R.layout.tablelist, null ,false); alertDialog.setView(convertView); ListView lv = (ListView) convertView.findViewById(R.id.list); CustomAlertAdapter adapter = new CustomAlertAdapter(AddEventActivity.this, (ArrayList<String>)tables); lv.setAdapter(adapter); alertDialog.setSingleChoiceItems(adapter,selected, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { ListView lw = ((AlertDialog)dialog).getListView(); Object checkedItem = lw.getAdapter().getItem(lw.getCheckedItemPosition()); txtTable.setText(String.valueOf(checkedItem)); dialog.dismiss(); } }); alertDialog.show(); } }); ``` customAlertAdapter ``` public class CustomAlertAdapter extends BaseAdapter{ Context ctx=null; ArrayList<String> listarray=null; private LayoutInflater mInflater=null; public CustomAlertAdapter(Activity activty,ArrayList<String> list) { this.ctx=activty; mInflater = activty.getLayoutInflater(); this.listarray=list; } @Override public int getCount() { return listarray.size(); } @Override public Object getItem(int arg0) { return null; } @Override public long getItemId(int arg0) { return 0; } @Override public View getView(int position, View convertView, ViewGroup arg2) { final ViewHolder holder; if (convertView == null ) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.alertlistrow, null); holder.titlename = (TextView) convertView.findViewById(R.id.tableTitle); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } String datavalue=listarray.get(position); holder.titlename.setText(datavalue); return convertView; } private static class ViewHolder { TextView titlename; } ``` alertlistrow layout : ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1" android:orientation="vertical" android:measureWithLargestChild="false"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white"> <Button android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="center|right" android:background="@drawable/circle_shape" android:id="@+id/selectColor" android:layout_alignTop="@+id/switch2" android:layout_alignParentStart="true" android:layout_marginLeft="20dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="@android:style/TextAppearance.Medium" android:id="@+id/tableTitle" android:layout_alignParentLeft="false" android:layout_alignParentStart="false" android:layout_centerVertical="true" android:layout_toRightOf="@+id/selectColor" android:layout_marginLeft="10dp" /> </RelativeLayout> </LinearLayout> ```
2016/03/03
[ "https://Stackoverflow.com/questions/35764231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5881997/" ]
It is for forward declarations; imagine two classes having a pointer or mention to each other's instances: ``` class A; class B; class A { class B*ptr; int x; /// etc }; class B : A { std::string s; std::vector<A> v; //// etc }; ``` It is also useful for readability; you might want to list all the classes first in some header. And you could just forward declare a class and simply use its pointers without defining that class. BTW, C99 has similar forward declarations for `struct`, `union`; and it is also useful to forward declare functions.
That is a [forward declaration](https://stackoverflow.com/questions/553682/when-can-i-use-a-forward-declaration), which is a method for dealing with circular dependencies in header files. For example if two classes each hold a pointer to another, then you need to forward declare the class that is defined further down in the translation unit.
35,764,231
I am implementing custom list view in alert dialog. It's not showing up any view. I have created one query to get the list of titles from table. I want to show this list in alert dialog. What's going wrong? alert dialog : ``` selectTable.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int selected = 0; TimeTableHelper th = new TimeTableHelper(getApplicationContext()); final List<String> tables = new ArrayList<String>(th.getTitle()); AlertDialog.Builder alertDialog = new AlertDialog.Builder(AddEventActivity.this); LayoutInflater inflater = getLayoutInflater(); View convertView = (View) inflater.inflate(R.layout.tablelist, null ,false); alertDialog.setView(convertView); ListView lv = (ListView) convertView.findViewById(R.id.list); CustomAlertAdapter adapter = new CustomAlertAdapter(AddEventActivity.this, (ArrayList<String>)tables); lv.setAdapter(adapter); alertDialog.setSingleChoiceItems(adapter,selected, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { ListView lw = ((AlertDialog)dialog).getListView(); Object checkedItem = lw.getAdapter().getItem(lw.getCheckedItemPosition()); txtTable.setText(String.valueOf(checkedItem)); dialog.dismiss(); } }); alertDialog.show(); } }); ``` customAlertAdapter ``` public class CustomAlertAdapter extends BaseAdapter{ Context ctx=null; ArrayList<String> listarray=null; private LayoutInflater mInflater=null; public CustomAlertAdapter(Activity activty,ArrayList<String> list) { this.ctx=activty; mInflater = activty.getLayoutInflater(); this.listarray=list; } @Override public int getCount() { return listarray.size(); } @Override public Object getItem(int arg0) { return null; } @Override public long getItemId(int arg0) { return 0; } @Override public View getView(int position, View convertView, ViewGroup arg2) { final ViewHolder holder; if (convertView == null ) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.alertlistrow, null); holder.titlename = (TextView) convertView.findViewById(R.id.tableTitle); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } String datavalue=listarray.get(position); holder.titlename.setText(datavalue); return convertView; } private static class ViewHolder { TextView titlename; } ``` alertlistrow layout : ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1" android:orientation="vertical" android:measureWithLargestChild="false"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white"> <Button android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="center|right" android:background="@drawable/circle_shape" android:id="@+id/selectColor" android:layout_alignTop="@+id/switch2" android:layout_alignParentStart="true" android:layout_marginLeft="20dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="@android:style/TextAppearance.Medium" android:id="@+id/tableTitle" android:layout_alignParentLeft="false" android:layout_alignParentStart="false" android:layout_centerVertical="true" android:layout_toRightOf="@+id/selectColor" android:layout_marginLeft="10dp" /> </RelativeLayout> </LinearLayout> ```
2016/03/03
[ "https://Stackoverflow.com/questions/35764231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5881997/" ]
That is a [forward declaration](https://stackoverflow.com/questions/553682/when-can-i-use-a-forward-declaration), which is a method for dealing with circular dependencies in header files. For example if two classes each hold a pointer to another, then you need to forward declare the class that is defined further down in the translation unit.
You are asking about need for forward declaration. Imagine following hypothetical example: ``` class Man { Woman mySpouse; }; class Woman { Man mySpouse; }; ``` > > we must definite a class before we use it. > > > Yes. So you can see for above example, this is impossible chicken-egg situation (aka circular dependency). This is why you need forward declaration and pointers, as shown below: ``` class Man; // Forward declaration class Woman; // Forward declaration class Man { Woman * pMySpouse; }; class Woman { Man * pMySpouse; }; ``` Thanks to forward declaration, this should work OK. See answers to this question : [When can I use a forward declaration?](https://stackoverflow.com/questions/553682/when-can-i-use-a-forward-declaration)
35,764,231
I am implementing custom list view in alert dialog. It's not showing up any view. I have created one query to get the list of titles from table. I want to show this list in alert dialog. What's going wrong? alert dialog : ``` selectTable.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int selected = 0; TimeTableHelper th = new TimeTableHelper(getApplicationContext()); final List<String> tables = new ArrayList<String>(th.getTitle()); AlertDialog.Builder alertDialog = new AlertDialog.Builder(AddEventActivity.this); LayoutInflater inflater = getLayoutInflater(); View convertView = (View) inflater.inflate(R.layout.tablelist, null ,false); alertDialog.setView(convertView); ListView lv = (ListView) convertView.findViewById(R.id.list); CustomAlertAdapter adapter = new CustomAlertAdapter(AddEventActivity.this, (ArrayList<String>)tables); lv.setAdapter(adapter); alertDialog.setSingleChoiceItems(adapter,selected, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { ListView lw = ((AlertDialog)dialog).getListView(); Object checkedItem = lw.getAdapter().getItem(lw.getCheckedItemPosition()); txtTable.setText(String.valueOf(checkedItem)); dialog.dismiss(); } }); alertDialog.show(); } }); ``` customAlertAdapter ``` public class CustomAlertAdapter extends BaseAdapter{ Context ctx=null; ArrayList<String> listarray=null; private LayoutInflater mInflater=null; public CustomAlertAdapter(Activity activty,ArrayList<String> list) { this.ctx=activty; mInflater = activty.getLayoutInflater(); this.listarray=list; } @Override public int getCount() { return listarray.size(); } @Override public Object getItem(int arg0) { return null; } @Override public long getItemId(int arg0) { return 0; } @Override public View getView(int position, View convertView, ViewGroup arg2) { final ViewHolder holder; if (convertView == null ) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.alertlistrow, null); holder.titlename = (TextView) convertView.findViewById(R.id.tableTitle); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } String datavalue=listarray.get(position); holder.titlename.setText(datavalue); return convertView; } private static class ViewHolder { TextView titlename; } ``` alertlistrow layout : ``` <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1" android:orientation="vertical" android:measureWithLargestChild="false"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white"> <Button android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="center|right" android:background="@drawable/circle_shape" android:id="@+id/selectColor" android:layout_alignTop="@+id/switch2" android:layout_alignParentStart="true" android:layout_marginLeft="20dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="@android:style/TextAppearance.Medium" android:id="@+id/tableTitle" android:layout_alignParentLeft="false" android:layout_alignParentStart="false" android:layout_centerVertical="true" android:layout_toRightOf="@+id/selectColor" android:layout_marginLeft="10dp" /> </RelativeLayout> </LinearLayout> ```
2016/03/03
[ "https://Stackoverflow.com/questions/35764231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5881997/" ]
It is for forward declarations; imagine two classes having a pointer or mention to each other's instances: ``` class A; class B; class A { class B*ptr; int x; /// etc }; class B : A { std::string s; std::vector<A> v; //// etc }; ``` It is also useful for readability; you might want to list all the classes first in some header. And you could just forward declare a class and simply use its pointers without defining that class. BTW, C99 has similar forward declarations for `struct`, `union`; and it is also useful to forward declare functions.
You are asking about need for forward declaration. Imagine following hypothetical example: ``` class Man { Woman mySpouse; }; class Woman { Man mySpouse; }; ``` > > we must definite a class before we use it. > > > Yes. So you can see for above example, this is impossible chicken-egg situation (aka circular dependency). This is why you need forward declaration and pointers, as shown below: ``` class Man; // Forward declaration class Woman; // Forward declaration class Man { Woman * pMySpouse; }; class Woman { Man * pMySpouse; }; ``` Thanks to forward declaration, this should work OK. See answers to this question : [When can I use a forward declaration?](https://stackoverflow.com/questions/553682/when-can-i-use-a-forward-declaration)
46,007,887
I want to highlight tiles in range of a unit which is placed in a system of hexagonal tiles. For example if I place a unit with range=2 on 6|5, I want to highlight 5|4, 6|4, 7|4, 7|5, 6|6, 5|5, 4|5, 4|4, 5|3 and so on... [![example map](https://i.stack.imgur.com/Kp2vy.jpg)](https://i.stack.imgur.com/Kp2vy.jpg) How can I calculate those coordinates from the origin coordinate and the range? At the moment I use many if clauses to check every possibility like this: ``` if (gameField[x, y].IsHighlighted && gameField[x, y].DeployedUnit != null) { if (gameField[x, y].DeployedUnit.AttackRange > 0) { if (x % 2 == 0) { if (x > 0 && y > 0) { gameField[x - 1, y - 1].IsGreenRange = true; } if (x > 0) { gameField[x - 1, y].IsGreenRange = true; } if (y < height - 1) { gameField[x, y + 1].IsGreenRange = true; } if (x < length - 1) { gameField[x + 1, y].IsGreenRange = true; } if (x < length - 1 && y > 0) { gameField[x + 1, y - 1].IsGreenRange = true; } if (y > 0) { gameField[x, y - 1].IsGreenRange = true; } } else { [...] } } } ``` But with increasing range, the complexity also increases... There has to be a better way. Any ideas?
2017/09/01
[ "https://Stackoverflow.com/questions/46007887", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1760135/" ]
Recursion. Same as you would for illuminating which hexes you can reach by movement.
Thanks to MartinB, I tried the recursive approach and it worked like a charm. :) ``` private void HighlightRange(int originX, int originY, int range, bool greenRange = true) { if (range > 0) { List<Tuple<int, int>> hexCoordinates = new List<Tuple<int, int>>(); if (originX % 2 == 0) { hexCoordinates.Add(new Tuple<int, int>(originX, originY - 1)); hexCoordinates.Add(new Tuple<int, int>(originX - 1, originY - 1)); hexCoordinates.Add(new Tuple<int, int>(originX - 1, originY)); hexCoordinates.Add(new Tuple<int, int>(originX, originY + 1)); hexCoordinates.Add(new Tuple<int, int>(originX + 1, originY)); hexCoordinates.Add(new Tuple<int, int>(originX + 1, originY - 1)); } else { hexCoordinates.Add(new Tuple<int, int>(originX, originY - 1)); hexCoordinates.Add(new Tuple<int, int>(originX - 1, originY)); hexCoordinates.Add(new Tuple<int, int>(originX - 1, originY + 1)); hexCoordinates.Add(new Tuple<int, int>(originX, originY + 1)); hexCoordinates.Add(new Tuple<int, int>(originX + 1, originY + 1)); hexCoordinates.Add(new Tuple<int, int>(originX + 1, originY)); } hexCoordinates.RemoveAll(t => (t.Item1 < 0 || t.Item1 >= length || t.Item2 < 0 || t.Item2 >= height)); while (hexCoordinates.Count > 0) { if (range > 1) { HighlightRange(hexCoordinates[0].Item1, hexCoordinates[0].Item2, range - 1, greenRange); } if (greenRange) { gameField[hexCoordinates[0].Item1, hexCoordinates[0].Item2].IsGreenRange = true; } else { gameField[hexCoordinates[0].Item1, hexCoordinates[0].Item2].IsRedRange = true; } hexCoordinates.RemoveAt(0); } } else { return; } } ```
16,506,851
I am searching a vector of vectors for a specific int. ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = { val x = vectors.indexWhere(_.indexWhere(_ == i)) val y = vectors(x).indexOf(y) (x, y) } ``` You can see I get the y twice. Firstly when computing x and then again when computing y. Not good. How do I do it so I only compute y once? Thanks
2013/05/12
[ "https://Stackoverflow.com/questions/16506851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1114773/" ]
The one approach you can take is to just iterate all vectors: ``` def searchVectors(x: Int, vec: Vector[Vector[Int]]) = for { i <- 0 until vec.size j <- 0 until vec(i).size if vec(i)(j) == x } yield (i, j) ``` Vector also have `zipWithIndex` method, which adds index to each element of the collection and creates a tuple of them. So you can use it in order to archive the same thing: ``` def searchVectors(x: Int, vec: Vector[Vector[Int]]) = for { (subVec, i) <- vec.zipWithIndex (elem, j) <- subVec.zipWithIndex if elem == x } yield (i, j) ``` The advantage of this approach, is that instead of external (index-based) loop, you are using internal loop with `map`/`flatMap`. If you will combine it with views, then you can implement lazy search: ``` def searchVectors(x: Int, vec: Vector[Vector[Int]]) = for { (subVec, i) <- vec.view.zipWithIndex (elem, j) <- subVec.view.zipWithIndex if elem == x } yield (i, j) ``` Not you will still receive collection of results, but it's lazy collection. So if you will take it's head like this: ``` searchVectors(3, vector).headOption ``` It will actually perform search (only at this point) and then, when it's found, it would be returned as `Option`. No further search will be performed.
Here is a more functional approach to do it: ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = { val outer = vectors.toStream map (_.indexOf(i)) outer.zipWithIndex.filter(_._1 != -1).headOption map (_.swap) } ``` EDIT: I think I like this even better: ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = { vectors.toStream.map(_.indexOf(i)).zipWithIndex.collectFirst { case (y, x) if y != -1 => (x, y) } } ``` Converting to a `Stream` is optional, but probably more efficient because it avoids searching the whole vector if the desired element has already been found.
16,506,851
I am searching a vector of vectors for a specific int. ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = { val x = vectors.indexWhere(_.indexWhere(_ == i)) val y = vectors(x).indexOf(y) (x, y) } ``` You can see I get the y twice. Firstly when computing x and then again when computing y. Not good. How do I do it so I only compute y once? Thanks
2013/05/12
[ "https://Stackoverflow.com/questions/16506851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1114773/" ]
The one approach you can take is to just iterate all vectors: ``` def searchVectors(x: Int, vec: Vector[Vector[Int]]) = for { i <- 0 until vec.size j <- 0 until vec(i).size if vec(i)(j) == x } yield (i, j) ``` Vector also have `zipWithIndex` method, which adds index to each element of the collection and creates a tuple of them. So you can use it in order to archive the same thing: ``` def searchVectors(x: Int, vec: Vector[Vector[Int]]) = for { (subVec, i) <- vec.zipWithIndex (elem, j) <- subVec.zipWithIndex if elem == x } yield (i, j) ``` The advantage of this approach, is that instead of external (index-based) loop, you are using internal loop with `map`/`flatMap`. If you will combine it with views, then you can implement lazy search: ``` def searchVectors(x: Int, vec: Vector[Vector[Int]]) = for { (subVec, i) <- vec.view.zipWithIndex (elem, j) <- subVec.view.zipWithIndex if elem == x } yield (i, j) ``` Not you will still receive collection of results, but it's lazy collection. So if you will take it's head like this: ``` searchVectors(3, vector).headOption ``` It will actually perform search (only at this point) and then, when it's found, it would be returned as `Option`. No further search will be performed.
This bothered me too. You may have already thought of this, but if you are willing to violate the functional programming principle of immutable state etc. here is one possible approach: ``` val v = Vector(Vector(1,2,3), Vector(4, 5, 6)) var c: Int = -1 val r = v.indexWhere(r => {c = r.indexOf(6); c != -1}) (r, c) ```
16,506,851
I am searching a vector of vectors for a specific int. ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = { val x = vectors.indexWhere(_.indexWhere(_ == i)) val y = vectors(x).indexOf(y) (x, y) } ``` You can see I get the y twice. Firstly when computing x and then again when computing y. Not good. How do I do it so I only compute y once? Thanks
2013/05/12
[ "https://Stackoverflow.com/questions/16506851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1114773/" ]
The one approach you can take is to just iterate all vectors: ``` def searchVectors(x: Int, vec: Vector[Vector[Int]]) = for { i <- 0 until vec.size j <- 0 until vec(i).size if vec(i)(j) == x } yield (i, j) ``` Vector also have `zipWithIndex` method, which adds index to each element of the collection and creates a tuple of them. So you can use it in order to archive the same thing: ``` def searchVectors(x: Int, vec: Vector[Vector[Int]]) = for { (subVec, i) <- vec.zipWithIndex (elem, j) <- subVec.zipWithIndex if elem == x } yield (i, j) ``` The advantage of this approach, is that instead of external (index-based) loop, you are using internal loop with `map`/`flatMap`. If you will combine it with views, then you can implement lazy search: ``` def searchVectors(x: Int, vec: Vector[Vector[Int]]) = for { (subVec, i) <- vec.view.zipWithIndex (elem, j) <- subVec.view.zipWithIndex if elem == x } yield (i, j) ``` Not you will still receive collection of results, but it's lazy collection. So if you will take it's head like this: ``` searchVectors(3, vector).headOption ``` It will actually perform search (only at this point) and then, when it's found, it would be returned as `Option`. No further search will be performed.
Here's a easy-to-understand solution ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]): (Int, Int) = { val row = vectors.indexWhere(_.contains(i)) // Try to get index of vector containing element if (row > -1) (row, vectors(row).indexOf(i)) // (row, col) else (-1, -1) } ```
16,506,851
I am searching a vector of vectors for a specific int. ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = { val x = vectors.indexWhere(_.indexWhere(_ == i)) val y = vectors(x).indexOf(y) (x, y) } ``` You can see I get the y twice. Firstly when computing x and then again when computing y. Not good. How do I do it so I only compute y once? Thanks
2013/05/12
[ "https://Stackoverflow.com/questions/16506851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1114773/" ]
Here is a more functional approach to do it: ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = { val outer = vectors.toStream map (_.indexOf(i)) outer.zipWithIndex.filter(_._1 != -1).headOption map (_.swap) } ``` EDIT: I think I like this even better: ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = { vectors.toStream.map(_.indexOf(i)).zipWithIndex.collectFirst { case (y, x) if y != -1 => (x, y) } } ``` Converting to a `Stream` is optional, but probably more efficient because it avoids searching the whole vector if the desired element has already been found.
Here's a easy-to-understand solution ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]): (Int, Int) = { val row = vectors.indexWhere(_.contains(i)) // Try to get index of vector containing element if (row > -1) (row, vectors(row).indexOf(i)) // (row, col) else (-1, -1) } ```
16,506,851
I am searching a vector of vectors for a specific int. ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]) = { val x = vectors.indexWhere(_.indexWhere(_ == i)) val y = vectors(x).indexOf(y) (x, y) } ``` You can see I get the y twice. Firstly when computing x and then again when computing y. Not good. How do I do it so I only compute y once? Thanks
2013/05/12
[ "https://Stackoverflow.com/questions/16506851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1114773/" ]
This bothered me too. You may have already thought of this, but if you are willing to violate the functional programming principle of immutable state etc. here is one possible approach: ``` val v = Vector(Vector(1,2,3), Vector(4, 5, 6)) var c: Int = -1 val r = v.indexWhere(r => {c = r.indexOf(6); c != -1}) (r, c) ```
Here's a easy-to-understand solution ``` def searchVectors(i: Int, vectors: Vector[Vector[Int]]): (Int, Int) = { val row = vectors.indexWhere(_.contains(i)) // Try to get index of vector containing element if (row > -1) (row, vectors(row).indexOf(i)) // (row, col) else (-1, -1) } ```
18,318,272
This is probably a very easy question but let's say I have a php json\_encoded javascript object of this form: ``` var js_objet = { "1": { "Users": { "id": "14", "name": "Peter" }, "Children": [ { id: 17, name: "Paul" }, { id: 18, name: "Mathew" } ] } } ``` What is the synthax to get the name of the child with id 18 (Mathew) for example from that Object? Thank you
2013/08/19
[ "https://Stackoverflow.com/questions/18318272", "https://Stackoverflow.com", "https://Stackoverflow.com/users/765368/" ]
Here's such a custom function as mentioned earlier. ``` function getChildrenById(id){ for (var child in js_objet[1].Children){ if(id == js_objet[1].Children[child].id){ return js_objet[1].Children[child].name; } } return false; } ``` running `getChildrenById(18)` would return "Mathew" Hope that helps, R.
You can do it like this: ``` var name = js_objet["1"].Children[1].name; ``` [JSFiddle available here](http://jsfiddle.net/4uRRk/)
18,318,272
This is probably a very easy question but let's say I have a php json\_encoded javascript object of this form: ``` var js_objet = { "1": { "Users": { "id": "14", "name": "Peter" }, "Children": [ { id: 17, name: "Paul" }, { id: 18, name: "Mathew" } ] } } ``` What is the synthax to get the name of the child with id 18 (Mathew) for example from that Object? Thank you
2013/08/19
[ "https://Stackoverflow.com/questions/18318272", "https://Stackoverflow.com", "https://Stackoverflow.com/users/765368/" ]
Here's such a custom function as mentioned earlier. ``` function getChildrenById(id){ for (var child in js_objet[1].Children){ if(id == js_objet[1].Children[child].id){ return js_objet[1].Children[child].name; } } return false; } ``` running `getChildrenById(18)` would return "Mathew" Hope that helps, R.
This is how I would approach this problem: ``` var id = 18; var name = ''; var jsObjIndex = "1"; var jsObjAttr = "Children" for (var i = 0; i < js_objet[jsObjIndex][jsObjAttr].length; i++) { if (js_objet[jsObjIndex][jsObjAttr][i].id == id) { name = js_objet[jsObjIndex][jsObjAttr][i].name; break; } } ``` You are basically performing a linear search on every element of jsObjIndex.Children. There are likely better solutions however :).
18,318,272
This is probably a very easy question but let's say I have a php json\_encoded javascript object of this form: ``` var js_objet = { "1": { "Users": { "id": "14", "name": "Peter" }, "Children": [ { id: 17, name: "Paul" }, { id: 18, name: "Mathew" } ] } } ``` What is the synthax to get the name of the child with id 18 (Mathew) for example from that Object? Thank you
2013/08/19
[ "https://Stackoverflow.com/questions/18318272", "https://Stackoverflow.com", "https://Stackoverflow.com/users/765368/" ]
Here's such a custom function as mentioned earlier. ``` function getChildrenById(id){ for (var child in js_objet[1].Children){ if(id == js_objet[1].Children[child].id){ return js_objet[1].Children[child].name; } } return false; } ``` running `getChildrenById(18)` would return "Mathew" Hope that helps, R.
This really is a comment, but I don't have enough reputation (but it's relevant as I recently encountered the same issue): This would probably be easier to do if you can change the JSON format to use the ID as the key for each child object: ``` var js_objet = { "1": { "Users": { "id": "14", "name": "Peter" }, "Children": { "17":{ "name": "Paul" }, "18":{ "name": "Mathew" } } } } ``` Then you can simply call it using ``` js_objet[1].Children[18].name; ``` This is assuming each ID is unique.
31,172,861
I have two arrays of the same length, say array x and array y. I want to find the value of y corresponding to x=0.56. This is not a value present in array x. I would like python to find by itself the closest value larger than 0.56 (and its corresponding y value) and the closest value smaller than 0.56 (and its corresponding y value). Then simply interpolate to find the value of y when x 0.56. This is easily done when I find the indices of the two x values and corresponding y values by myself and input them into Python (see following bit of code). But is there any way for python to find the indices by itself? ``` #interpolation: def effective_height(h1,h2,g1,g2): return (h1 + (((0.56-g1)/(g2-g1))*(h2-h1))) eff_alt1 = effective_height(x[12],x[13],y[12],y[13]) ``` In this bit of code, I had to find the indices [12] and [13] corresponding to the closest smaller value to 0.56 and the closest larger value to 0.56. > > Now I am looking for a similar technique where I would just tell python to interpolate between the two values of x for x=0.56 and print the corresponding value of y when x=0.56. > > > I have looked at scipy's interpolate but don't think it would help in this case, although further clarification on how I can use it in my case would be helpful too.
2015/07/01
[ "https://Stackoverflow.com/questions/31172861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2813228/" ]
Does Numpy `interp` do what you want?: ``` import numpy as np x = [0,1,2] y = [2,3,4] np.interp(0.56, x, y) Out[81]: 2.56 ```
Given your two arrays, `x` and `y`, you can do something like the following using SciPy. ``` from scipy.interpolate import InterpolatedUnivariateSpline spline = InterpolatedUnivariateSpline(x, y, k=5) spline(0.56) ``` The keyword `k` must be between 1 and 5, and [controls the degree of the spline](http://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.interpolate.InterpolatedUnivariateSpline.html#scipy.interpolate.InterpolatedUnivariateSpline). Example: ``` >>> x = range(10) >>> y = range(0, 100, 10) >>> spline = InterpolatedUnivariateSpline(x, y, k=5) >>> spline(0.56) array(5.6000000000000017) ```
47,245
I have a big insert script I need to run. Its about 55,000 records and 160 columns. The script is already created and I can't create it again. The problem I have is that this runs for about 4 hours or so, and during that time the system that uses this database gets really slow and timeout a lot. I would not care if my INSERT is slower but it shouldn't impact other users. I was thinking in doing some batch of let's say 500 rows and use the `WAITFOR`, but was wondering if there could be a better option for doing this.
2013/07/29
[ "https://dba.stackexchange.com/questions/47245", "https://dba.stackexchange.com", "https://dba.stackexchange.com/users/20328/" ]
Break the operation into chunks of separate transactions. ``` BEGIN TRANSACTION; INSERT ... INSERT ... -- maybe 1000 or 2500 of these COMMIT TRANSACTION; GO WAITFOR DELAY '00:00:01'; GO BEGIN TRANSACTION; INSERT ... INSERT ... -- maybe 1000 or 2500 more of these COMMIT TRANSACTION; ``` This will prevent all 55,000 inserts from jamming up your log and operating as a single, blocking transaction. I talked about this methodology to some degree in [this blog post](http://www.sqlperformance.com/2013/03/io-subsystem/chunk-deletes) even though it talks about more tightly controlled `DELETE` operations. If you can, have the file(s) regenerated in a format that makes them easier to `BULK INSERT` or bcp.
Without knowing more about the system, doing small batches and then wait for a few milli seconds will usually significantly reduce contention. However, you need to be aware that it will significantly slow down the insert. Make sure you do not have transactions that span your batches or you will make things much worse.
22,417,958
I encounter the problem that even though after installing gdb Eclipse still gives out the error message 'Error with command --gdb version' whenever I try to compile my code. I exactly followed this guide: [Eclipse GDB MacOSX Mavericks](https://stackoverflow.com/questions/19877047/eclipse-gdb-macosx-mavericks), but it didn't fix it. Any ideas what else could be wrong?
2014/03/15
[ "https://Stackoverflow.com/questions/22417958", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3421936/" ]
As indicated in the answer from where you took that code, Apple recommends to refresh the receipt if validation fails. This is what `RMStore` does to validate a receipt/transaction: ``` RMAppReceipt *receipt = [RMAppReceipt bundleReceipt]; const BOOL verified = [self verifyTransaction:transaction inReceipt:receipt success:successBlock failure:nil]; // failureBlock is nil intentionally. See below. if (verified) return; // Apple recommends to refresh the receipt if validation fails on iOS [[RMStore defaultStore] refreshReceiptOnSuccess:^{ RMAppReceipt *receipt = [RMAppReceipt bundleReceipt]; [self verifyTransaction:transaction inReceipt:receipt success:successBlock failure:failureBlock]; } failure:^(NSError *error) { [self failWithBlock:failureBlock error:error]; }]; ```
I'll just add one thing here - took me a while to figure out why my hash is mismatching... receipt bundleId example: ASN1 OCTET STRING (27 byte) 0C19636F6D2E706177656C6B6C61707563682E536B696E4578616D Which is actually made of Identifier (0C), length (19) and value (63..6D). **For comparing app.bundleId == receipt.bundleId -> use value only For generating hash -> use the whole ASN1 buffer (otherwise SHA1 will result in different value)**
10,903,164
I am new to Python. First, the code is supposed to take an input (in the form of "x/y/z" where x,y, and z are any positive integer) and split it into three different variables. ``` input = raw_input() a, b, c = input.split("/", 2) ``` I want the second part of my code to take these three variables and sort them based on their numerical value. ``` order = [a, b, c] print order order.sort() print order ``` While this works perfectly for most inputs, I have found that for inputs "23/9/2" and "43/8/2" the output has not been sorted so is not returned in the correct order. Any thoughts as to what could be causing inputs such as these to not work?
2012/06/05
[ "https://Stackoverflow.com/questions/10903164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1438105/" ]
The issue is that you are sorting strings, and expecting them to be sorted like integers. First convert your list of strings to a list of ints if you would like numerical sorting. ``` >>> sorted(['23', '9', '2']) ['2', '23', '9'] >>> sorted(map(int, ['23', '9', '2'])) [2, 9, 23] ``` Here is how you could rewrite your code: ``` input = raw_input() a, b, c = map(int, input.split("/", 2)) order = [a, b, c] print order order.sort() print order ``` If you need to convert them back to strings, just use `map(str, order)`. Note that on Python 2.x `map()` returns a list and on 3.x it will return a generator.
You are sorting strings but you should be sorting integers. So you have to convert each string to an integer using `int`: ``` order = [int(a), int(b), int(c)] ```
23,135,187
I was implementing a Java application when I came across this scenario and couldn't find which way is better to do it and why. following is the scenario. I have a static list that will load data on application startup. In my ApplicationStartup class I have ``` public static List<Map<String,Object>> stockSymbolsListMap; ``` Now when I load this List using a function in my Utility class I have the following code: ``` //Check if the list has been initialized or not if(ApplicationStartup.stockSymbolsListMap == null){ ApplicationStartup.stockSymbolsListMap = new ArrayList<Map<String,Object>>(); } else if(!(ApplicationStartup.stockSymbolsListMap.isEmpty())){ // Clear the list to avoid redundancy ApplicationStartup.stockSymbolsListMap.clear(); } // Adding all stock symbols to the list while(allStockSymbols.hasNext()){ ApplicationStartup.stockSymbolsListMap.add(allStockSymbols.next().toMap()); } ``` Isn't it better that I initialize this list in my ApplicationStartup class itself? ``` public static List<Map<String,Object>> stockSymbolsListMap = new ArrayList<Map<String,Object>>(); ```
2014/04/17
[ "https://Stackoverflow.com/questions/23135187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3045515/" ]
Although this question has been answered, please allow me to add a few things: When examining the source of `and`, you get: ``` and :: [Bool] -> Bool and = foldr (&&) True ``` First thing to notice is that `and` takes a list of Boolean variables, and returns a single Boolean variable, and that the expression `x mod y /= 0` evaluates to True or False (Hence fitting the [Bool] requirement) . More important to notice is that `foldr` is a lazy-fold. So a lazy fold here is optimal because `&&` is a semi-strict operator. Hence a lazy fold in combination with a semi-strict operator will yield a short-circuit evaluation upon encountering the first occurence of a `False`. Hence in the cases of actual *non-prime numbers*, `and` will avoid evaluating the entire list, consequently saving you time as a result. Don't take my word for it, define your own strict version of `and` if you want (using the stricter `foldl`): ``` andStrict :: [Bool] -> Bool andStrict x = foldl (&&) True primeStrict :: (Integral a) => a -> Bool primeStrict x = andStrict [x `mod` y /= 0 | y <- [2..(x-1)]] ``` Now run: ``` prime 2000000000 ``` Notice how that was fast? Now do this, but interrupt it before it crashes your memory-stack: ``` primeStrict 2000000000 ``` That was obviously slower, you were able to interrupt it. This is the role of `and`, and that is why `and` was written with `foldr`, and hence why it was chosen for the example code you posted. Hope that helps as a supportive answer.
`and` performs a *logical and* operation on all elements of a list. Primes are only divisible by one and themselves; this means that as soon as a divisor (without a remainder) exists between 2 inclusive and your `x` exclusive, the number is not a prime. The list comprehension generates a list of Boolean values that correspond to whether your `x` is or is not divisible by numbers from within the said range. As soon as any of them is false (a division occurred with a zero remainder), the number is not a prime. Consider: ``` x = 7 [7 % 2 /= 0 -> True, 7 % 3 /= -> True, ...] -- now applying and True && True && ... && True evaluates to True ``` `and` can be represented as a more general operation that can be performed on lists - a *fold* using *logical and*. Such as: `and' = foldr (&&) True`.
23,135,187
I was implementing a Java application when I came across this scenario and couldn't find which way is better to do it and why. following is the scenario. I have a static list that will load data on application startup. In my ApplicationStartup class I have ``` public static List<Map<String,Object>> stockSymbolsListMap; ``` Now when I load this List using a function in my Utility class I have the following code: ``` //Check if the list has been initialized or not if(ApplicationStartup.stockSymbolsListMap == null){ ApplicationStartup.stockSymbolsListMap = new ArrayList<Map<String,Object>>(); } else if(!(ApplicationStartup.stockSymbolsListMap.isEmpty())){ // Clear the list to avoid redundancy ApplicationStartup.stockSymbolsListMap.clear(); } // Adding all stock symbols to the list while(allStockSymbols.hasNext()){ ApplicationStartup.stockSymbolsListMap.add(allStockSymbols.next().toMap()); } ``` Isn't it better that I initialize this list in my ApplicationStartup class itself? ``` public static List<Map<String,Object>> stockSymbolsListMap = new ArrayList<Map<String,Object>>(); ```
2014/04/17
[ "https://Stackoverflow.com/questions/23135187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3045515/" ]
Although this question has been answered, please allow me to add a few things: When examining the source of `and`, you get: ``` and :: [Bool] -> Bool and = foldr (&&) True ``` First thing to notice is that `and` takes a list of Boolean variables, and returns a single Boolean variable, and that the expression `x mod y /= 0` evaluates to True or False (Hence fitting the [Bool] requirement) . More important to notice is that `foldr` is a lazy-fold. So a lazy fold here is optimal because `&&` is a semi-strict operator. Hence a lazy fold in combination with a semi-strict operator will yield a short-circuit evaluation upon encountering the first occurence of a `False`. Hence in the cases of actual *non-prime numbers*, `and` will avoid evaluating the entire list, consequently saving you time as a result. Don't take my word for it, define your own strict version of `and` if you want (using the stricter `foldl`): ``` andStrict :: [Bool] -> Bool andStrict x = foldl (&&) True primeStrict :: (Integral a) => a -> Bool primeStrict x = andStrict [x `mod` y /= 0 | y <- [2..(x-1)]] ``` Now run: ``` prime 2000000000 ``` Notice how that was fast? Now do this, but interrupt it before it crashes your memory-stack: ``` primeStrict 2000000000 ``` That was obviously slower, you were able to interrupt it. This is the role of `and`, and that is why `and` was written with `foldr`, and hence why it was chosen for the example code you posted. Hope that helps as a supportive answer.
The expression ``` [x `mod` y /= 0 | y <- [2..(x - 1)] ``` is a list of `Bool`s because `mod x y /= 0` (prefix notation because of backtick formatting) returns a `Bool`. The `and` function just does a logical AND of every element in a list, so ``` and [True, False] == False and [True, True] == True ```
54,993,833
I've debated with my friend about the difference between data structure stack and hardware stack(call stack). I thought they are perfectly same because they both have 'push' and 'pop' that can deal with only the latest element. But my friend said that they're not same at all, but they share only the same name, 'stack'. And he thinks so because in call stack, we can access addresses that are not the latest ones, contradicting the definition of stack(data structure). Can you give an answer to this?
2019/03/05
[ "https://Stackoverflow.com/questions/54993833", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` <?php $table='<table> <tr> <th>Id</th> <th>Name</th> <th>Serial</th> </tr>'; $servername = "localhost"; $username = ""; $password = ""; $dbname = "verify"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $result = $conn->query($sql); $stack = array(); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { array_push($stack, $row); if(!$array) { return $row; } } } $conn->close(); $table_content=''; foreach($stack as $item) { $table_content.= "<tr> <td>" . $row['ProductId'] . "</td> <td>" . $row['Name'] . " </td>. <td>" . $row['SerialId'] . "</td> </tr>"; } echo $table.$table_content.'</table>'; ?> ```
``` <table> <tr> <th>Id</th> <th>Name</th> <th>Serial</th> </tr> <?php $servername = "localhost"; $username = ""; $password = ""; $dbname = "verify"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $result = $conn->query($sql); $stack = array(); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { array_push($stack, $row); if(!$array) { return $row; } } } $conn->close(); foreach($stack as $item) { echo "<tr><td>" . $row['ProductId'] . "</td><td>" . $row['Name'] . "</td>. <td>" . $row['SerialId'] . "</td></tr>"; } ?> ```
30,400,601
I want to get the result of this query but I'm getting the following error > > Arithmetic overflow error converting expression to data type int > > > ``` SELECT d.name, ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
2015/05/22
[ "https://Stackoverflow.com/questions/30400601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1593500/" ]
Try converting to bigint: ``` SELECT d.name, ROUND(SUM(convert(bigint,mf.size)) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
It's breaking because when you sum mf.size, it exceeds the max number datatype int can hold which is 2,147,483,647. To fix it, just cast mf.size and alternatively \*8/1024 can be written as /128.0 like so: ``` SELECT d.name, ROUND(SUM(CAST(mf.size AS bigint))/128.0, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
30,400,601
I want to get the result of this query but I'm getting the following error > > Arithmetic overflow error converting expression to data type int > > > ``` SELECT d.name, ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
2015/05/22
[ "https://Stackoverflow.com/questions/30400601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1593500/" ]
Try converting to bigint: ``` SELECT d.name, ROUND(SUM(convert(bigint,mf.size)) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
Try this: ``` SELECT d.name, ROUND(SUM(CAST(mf.size as bigint)) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
30,400,601
I want to get the result of this query but I'm getting the following error > > Arithmetic overflow error converting expression to data type int > > > ``` SELECT d.name, ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
2015/05/22
[ "https://Stackoverflow.com/questions/30400601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1593500/" ]
Try converting to bigint: ``` SELECT d.name, ROUND(SUM(convert(bigint,mf.size)) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
Just replace `8` by `8.0` to cast result to numeric datatype. The error is because `size` column is `int` and `8` is also `int` so result of multiplication is `int`, but as `size` is close to `int type` upper bound 2147483647 you are overflowing the type by multiplication. ``` SELECT d.name, ROUND(SUM(mf.size) * 8.0 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ``` You can check it. This will throw exception: ``` DECLARE @i INT = 2147483647 SELECT @i + 1 ``` This works: ``` DECLARE @i INT = 2147483647 SELECT @i + 1.0 ``` You can read about type precedence <https://msdn.microsoft.com/en-us/library/ms190309.aspx>: > > When an operator combines two expressions of different data types, the > rules for data type precedence specify that the data type with the > lower precedence is converted to the data type with the higher > precedence. > > >
30,400,601
I want to get the result of this query but I'm getting the following error > > Arithmetic overflow error converting expression to data type int > > > ``` SELECT d.name, ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
2015/05/22
[ "https://Stackoverflow.com/questions/30400601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1593500/" ]
Just replace `8` by `8.0` to cast result to numeric datatype. The error is because `size` column is `int` and `8` is also `int` so result of multiplication is `int`, but as `size` is close to `int type` upper bound 2147483647 you are overflowing the type by multiplication. ``` SELECT d.name, ROUND(SUM(mf.size) * 8.0 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ``` You can check it. This will throw exception: ``` DECLARE @i INT = 2147483647 SELECT @i + 1 ``` This works: ``` DECLARE @i INT = 2147483647 SELECT @i + 1.0 ``` You can read about type precedence <https://msdn.microsoft.com/en-us/library/ms190309.aspx>: > > When an operator combines two expressions of different data types, the > rules for data type precedence specify that the data type with the > lower precedence is converted to the data type with the higher > precedence. > > >
It's breaking because when you sum mf.size, it exceeds the max number datatype int can hold which is 2,147,483,647. To fix it, just cast mf.size and alternatively \*8/1024 can be written as /128.0 like so: ``` SELECT d.name, ROUND(SUM(CAST(mf.size AS bigint))/128.0, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
30,400,601
I want to get the result of this query but I'm getting the following error > > Arithmetic overflow error converting expression to data type int > > > ``` SELECT d.name, ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
2015/05/22
[ "https://Stackoverflow.com/questions/30400601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1593500/" ]
Just replace `8` by `8.0` to cast result to numeric datatype. The error is because `size` column is `int` and `8` is also `int` so result of multiplication is `int`, but as `size` is close to `int type` upper bound 2147483647 you are overflowing the type by multiplication. ``` SELECT d.name, ROUND(SUM(mf.size) * 8.0 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ``` You can check it. This will throw exception: ``` DECLARE @i INT = 2147483647 SELECT @i + 1 ``` This works: ``` DECLARE @i INT = 2147483647 SELECT @i + 1.0 ``` You can read about type precedence <https://msdn.microsoft.com/en-us/library/ms190309.aspx>: > > When an operator combines two expressions of different data types, the > rules for data type precedence specify that the data type with the > lower precedence is converted to the data type with the higher > precedence. > > >
Try this: ``` SELECT d.name, ROUND(SUM(CAST(mf.size as bigint)) * 8 / 1024, 0) Size_MBs FROM sys.master_files mf INNER JOIN sys.databases d ON d.database_id = mf.database_id WHERE d.database_id > 4 GROUP BY d.name ORDER BY d.name ```
52,439,235
Im confused as to when a component should be used to render part of a page in react and when a function should be used. As per: [React Docs](https://reactjs.org/docs/jsx-in-depth.html) functions can be used within the render function which leads to one question: When should functions like this be used: ```js <> {this.renderAgreementForm(data)}</> ``` In this case the renderAgreementForm function is a class function that returns a large swath of the page's HTML and functionality. Should this ever be used over a component? Even when said component will not be reused?
2018/09/21
[ "https://Stackoverflow.com/questions/52439235", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10395461/" ]
Ultimately, whether you define a new component for your data or generate more HTML in an existing component is a design decision you have to make on a case-by-case bases. But there are some guiding principles: * [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) - Does the HTML and the code to create it belong to the core responsibility of the current component? If not, create a new one. * [Principle of Least Astonishment](https://en.wikipedia.org/wiki/Principle_of_least_astonishment) - Would another person be surprised to find the code in the existing component? If yes, create a new one. * [Open / Closed Principle](https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle) - Will your current components allow you to extend functionality in the future without changing existing code? If no, re-structure your components. My personal rule of thumb would be: If the function renders "large swaths of HTML" or does something non-trivial, I'd probably create a new component. I would use the inline functions for something like (i.e. trivial code): ``` render() { return <ul>{ listOfFriends.map(this.createFriendItem) }</li> } createFriendItem(f) { return <li><FriendShortView friend={f} /></li> } ```
Components should be used when you have "repeat code" such as a custom button or listview item. Anything else can be used as a typical function. This helps with readability and makes it easier to know what is page specific vs app "standard".
52,439,235
Im confused as to when a component should be used to render part of a page in react and when a function should be used. As per: [React Docs](https://reactjs.org/docs/jsx-in-depth.html) functions can be used within the render function which leads to one question: When should functions like this be used: ```js <> {this.renderAgreementForm(data)}</> ``` In this case the renderAgreementForm function is a class function that returns a large swath of the page's HTML and functionality. Should this ever be used over a component? Even when said component will not be reused?
2018/09/21
[ "https://Stackoverflow.com/questions/52439235", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10395461/" ]
Ultimately, whether you define a new component for your data or generate more HTML in an existing component is a design decision you have to make on a case-by-case bases. But there are some guiding principles: * [Single Responsibility Principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) - Does the HTML and the code to create it belong to the core responsibility of the current component? If not, create a new one. * [Principle of Least Astonishment](https://en.wikipedia.org/wiki/Principle_of_least_astonishment) - Would another person be surprised to find the code in the existing component? If yes, create a new one. * [Open / Closed Principle](https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle) - Will your current components allow you to extend functionality in the future without changing existing code? If no, re-structure your components. My personal rule of thumb would be: If the function renders "large swaths of HTML" or does something non-trivial, I'd probably create a new component. I would use the inline functions for something like (i.e. trivial code): ``` render() { return <ul>{ listOfFriends.map(this.createFriendItem) }</li> } createFriendItem(f) { return <li><FriendShortView friend={f} /></li> } ```
In the return part of the render function. ``` import ListWrapper from "./ListWrapper"; // components should be used directly showList() { return <li>item</li>; } // function or constants should be wrapped with `{}` render() { const inputValue = "value"; return ( <ListWrapper> { this.showList() } // <li>item</li> { inputValue } // value </ListWrapper> ); } ```
136,114
In order to solve a quite large system of differential equations, I have the habit to use the `NDSolve` command without changing any options. As I wanted more precision, I increased the number of points to integrate. There I get an error and suggestion to use `Method -> {"EquationSimplification" -> "Residual"}` in `NDSolve`... which I did and it works fine now. Can anyone explain to me how it really works and what's behind this method ?
2017/01/24
[ "https://mathematica.stackexchange.com/questions/136114", "https://mathematica.stackexchange.com", "https://mathematica.stackexchange.com/users/18982/" ]
This post contains several code blocks, you can copy them easily with the help of [`importCode`](https://mathematica.stackexchange.com/a/3537/1871). --- As mentioned in the comment above, the answer is hidden in [this tutorial](http://reference.wolfram.com/language/tutorial/NDSolveDAE.html). Given the tutorial is a bit obscure, I'd like to retell the relevant part in an easier to understand way. For illustration, let's consider the following initial value problem (IVP): $$ 2 y''(x)=y'(x)-3 y(x)-4 $$$$ y(0)=5,\ y'(0)=7 $$ ``` eqn = 2 y''[x] == y'[x] - 3 y[x] - 4; ic = {y[0] == 5, y'[0] == 7}; ``` We know this can be easily solved by `NDSolve` / `NDSolveValue`: ``` seq = Sequence[{eqn, ic}, y, {x, 0, 6}]; sol = NDSolveValue[seq]; ListLinePlot@sol ``` ![Mathematica graphics](https://i.stack.imgur.com/vlUtE.png) Nevertheless, do you know how `NDSolve` solves this problem? The process is quite involved of course, but the part relevant to your question is, `NDSolve` **needs** to transform the equation to some kind of *standard form*, which is controlled by `EquationSimplification`. Currently there exist 3 possible option values for `EquationSimplification`: `Solve`, `MassMatrix` and `Residual`. By default `NDSolve` will try `Solve` first. What does `Solve` do? It'll transform the equation to the following form: $$ y\_1'(x)=\frac{1}{2}(-3 y\_0(x)+y\_1(x)-4)$$ $$ y\_0'(x)=y\_1(x) $$ $$y\_0(0)=5,\ y\_1(0)=7$$ i.e. right hand side (RHS) of the resulting system consists no derivative term, and left hand side (LHS) of every equation is only a single 1st order derivative term whose coefficient is $1$. This can be verified with the following code: ``` {state} = NDSolve`ProcessEquations@seq; state[NumericalFunction][FunctionExpression] (* Function[{x, y, NDSolve`y$1$1}, {NDSolve`y$1$1, 1/2 (-4 - 3 y + NDSolve`y$1$1)}] *) Rule @@ (Flatten@state@# & /@ {Variables, WorkingVariables}) // Thread (* {x -> x, y -> y, y' -> NDSolve`y$1$1, …… *) ``` The system is then solved with an ordinary differential equation (ODE) solver. While when `Residual` is chosen (or [equivalently `SolveDelayed -> True`](https://mathematica.stackexchange.com/a/118528/1871) is set), the equation will be simply transformed to $$ 2 y''(x)-y'(x)+3 y(x)+4=0 $$$$ y(0)=5,\ y'(0)=7 $$ i.e. all the non-zero term in the equation is just moved to one side. This can be verified by: ``` {state2} = NDSolve`ProcessEquations[seq, SolveDelayed -> True]; state2[NumericalFunction][FunctionExpression] (* Function[{x, y, NDSolve`y$2$1, y$10678, NDSolve`y$2$1$10678}, {y$10678 - NDSolve`y$2$1, 4 + 3 y - NDSolve`y$2$1 + 2 NDSolve`y$2$1$10678}] *) Rule @@ (Flatten@state2@# & /@ {Variables, WorkingVariables}) // Thread (* {x -> x, y -> y, y' -> NDSolve`y$2$1, y' -> y$10678, y'' -> NDSolve`y$2$1$10678} *) ``` The equation is then solved with a differential algebraic equation (DAE) solver. Apparently, the former transformation is more complicated. When the equation to be transformed is intricate, or the equation system is very large, or the equation system just can't be transform to the desired form, this transformation can be rather time consuming or even never finishes. The following is a simple way to reproduce the issue mentioned in the question with *large* system, we just repeat `eqn` for `3 10^4` times: ``` $HistoryLength = 0; sys = With[{n = 3 10^4}, Unevaluated@Sequence[Table[{eqn, ic} /. y -> y@i, {i, n}], y /@ Range@n, {x, 0, 6}]]; NDSolve`ProcessEquations[sys] ``` > > **In *v9.0.1*:** ndsdtc: The time constraint of 1. seconds was exceeded trying to solve for derivatives, so the system will be treated as a system of differential-algebraic equations. You can use `Method->{"EquationSimplification"->"Solve"}` to have the system solved as ordinary differential equations. > > > **In *v11.2*:** ntdv: Cannot solve to find an explicit formula for the derivatives. Consider using the option `Method->{"EquationSimplification"->"Residual"}`. > > > As one can see, though the warning is different, `NDSolve` gives up transforming the equation system with `Solve` method in both cases. (The default `TimeConstraint` is `1`, actually. ) So, when setting `Method -> {"EquationSimplification" -> "Residual"}` / `SolveDelayed -> True`, you're turning to a cheaper transforming process for your equations. At this point, you may be thinking that "OK, I'll always use `SolveDelayed -> True` from now on", but I'm afraid it's not a good idea, because the DAE solver of `NDSolve` is generally weaker than the ODE solver. ([Here](https://mathematica.stackexchange.com/a/153833/1871) is an example.) In certain cases, one may still need to force `NDSolve` to solve equation with ODE solver, which may be troublesome. (Here is [an example](https://mathematica.stackexchange.com/q/131411/1871). ) Finally, notice there exist many issues related to `EquationSimplification -> Residual` and I've avoided talking about most of them in order to keep this answer clean. If you want to know more about the topic, search in this site.
When you choose the Method "Residual", Mathematica will convert an explicit equation like x''[t]==y'[t]+z[t] into the form 0==y'[t]+z[t]-x''[t] and use the solutions numerically closest to 0, since rounding errors would cause contradictions between the various explicit definitions in a set of long and numerically expensive functions when Mathematica gives the error message with the suggestion to use that Method.
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Yes, it's safe to say there is no such thing (Update: [look at that](https://photo.stackexchange.com/questions/5329/open-source-highly-scriptable-photo-management-platform-for-power-users-like/5339#5339), there might be, but with the level of performance you are asking?). Even [Gimp](http://www.gimp.org/) is not remotely close to Photoshop for advanced users, and the list of features you describe would put such an app in the "advanced" category. This is not true for all apps, Firefox was born after Internet Explorer and is definitely a competitor feature-wise. Photoshop is a monster though, and Adobe has tons of resources to throw at PS and Lightroom to make them the fantastic pieces of software engineering that they are. Moreover, the open source movement has Unix roots, and one old precept of that [philosophy](http://en.wikipedia.org/wiki/Unix_philosophy#Mike_Gancarz:_The_UNIX_Philosophy) is "Small is beautiful. Make each program do one thing well". The [link](http://osp.wikidot.com/the-big-picture) you provided exemplifies it well. There is a ton of small tools that you can use and that can form a chain to get you there, but this is *not* what makes Lightroom or Aperture attractive. The key to these applications is that they were designed by photographers for photographers as one coherent workflow. This lets you do 90% of simple to semi-advanced photo tasks from one single app using the same user interface. This saves people so much time! What I'm getting at is that this week you could get Lightroom for $150. This is *really* cheap for the time it will save you and the power behind that tool. If you are shooting RAW, this is hard to live without. This needs to be put in perspective too: it's half the price of my cheapest lens, and I have 3 lenses next to me that are almost 10 times the cost. I work in the open source business, and this how I've made a living for more than 10 years. We create advanced software (scientific viz, biomedical, supercomputing), but not out of thin air, we have to fund them, we have to pay salaries. The community helps but when it gets pretty sophisticated like this the learning curve can be steep. I don't see any competitor to Lightroom showing up anytime soon just from volunteers working on their free time, *with that level of performance*. Your first request, performance, is key for me here, because if it takes just 30% or 50% more time for me to process one photo, multiply that by 15,000+ pictures a year and the time I wasted completely justify buying a fast commercial app. I've seen open source apps focus on features, some on optimization/performance, rarely both (and I don't blame them). The race for Javascript performance in Firefox is pretty recent, for example. I pick (and support) open source software first, but when I need to get the job done and a tool has a clear lead, I (or my company) will put money to buy a reasonably priced shareware or commercial app. Pragmatism I guess. Now here is something I want to ask you honestly. How far did you use Lightroom? It seems you did, but I'm just asking. You mention that it is not up to what you want, but I'm a bit puzzled here: * It needs to be fast: LR is multi-threaded and uses multiple cores. I throw really big files at it (21MP) and I'm actually amazed its new denoise engine can work so fast. Advanced memory management, multi-threading, image processing, signal processing, you would need some serious fellows to beat that. I'm not saying it can't be faster (it's not GPU accelerated, to my knowledge), but if your app just chokes and page swap after 6MP, I've a problem. * Scriptability, Extensibility: the plugin framework in Lightroom is entirely scriptable. Plugins are scripts (it uses LUA). * Mangle filenames during important, based on camera metadata: LR does a lot of that. I have a precious preset that helps a lot, you can rename files at import by combining patterns and keywords that are replaced by metadata (unfortunately I don't see how to extract a substring of the original filename). See my [answer to another question](https://photo.stackexchange.com/questions/8/how-can-i-organise-my-photos-better/2957#2957) for more info. * Automatically apply EXIF and/or IPTC data during the import automatic importing: again, LR can do that (I apply a ton of info at import time, automatically). * Selecting images with arbitrary queries: you pretty much described Smart Collections in LR. Lot to love here. See my [answer to another question](https://photo.stackexchange.com/questions/4811/good-uses-for-lightrooms-smart-collections/4821#4821) for more info. * Keyboard-based interaction mode: there is a huge list of shortcuts in LR, it's actually a bit overwhelming. For even more flexibility, check [PADDY for Lightroom](http://sites.google.com/site/dorfl68/): free Key mapping, external keyboards, midi controllers, macros. * Ability to identify objects/people in photos: not in LR, but in Aperture I think. * Photo and/or meta-data manipulation on multiple devices: I think the new "Publish" services in LR3 would let you do that (i.e. they are not just "upload", they are more "hey, did that photo change, if yes then I need to push/publish it to other services somewhere").
Darktable (which you can download for OSX [here](http://www.darktable.org/install/#osx)) is probably the software that comes closest to what you are looking for. The workflow still has some rough edges, compared to Lightroom or Aperture, but quite usable especially if you are looking for a scripting interface.
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Wow, that's a long list. I think we can all be pretty safe in saying that there sure isn't anything like that now. One of the most interesting project that shares a lot of your goals is [F-Spot](http://f-spot.org/Goals) -- you might want to look at [getting involved](http://f-spot.org/Get_Involved) there. It's also worth noting that photo management features are on the "long-term roadmap" for the excellent raw converter [RawTherapee](http://www.rawtherapee.com/?mitem=1&artid=55), so that might an interesting place to direct some energy.
Here is my [import-and-mangle script](http://reidster.net/software/ptp-acquire); it's nothing special, but perhaps useful to look at. The mangling could be extended to include whatever exiftool can get its hands on.
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Have you taken a look at [Darktable](http://darktable.sourceforge.net/)? It seems to be open-source and Linux-only. Feature description ------------------- ### It needs to be fast It is quite quick and supports computations on the GPU using OpenCL. ### Scriptability It supports scripting using LUA. This is a pretty recent feature (as of '15), so the API is still small. ### Keyboard-based interaction mode You can do quite a few things using the keyboard. You have to check this yourself. ### Extensibility If you can't do it with Lua, you can hack the C code. Well... ### Real-time GUI manipulations Most filters are reasonably quick, so I think yes. ### Ability to identify objects/people in photos Nope ### Photo and/or meta-data manipulation on multiple devices It supports making temporary local copies of images on a remote drive for manipulation (and presumably back-syncing). I'm not using it this way, so I cannot comment much. ### Friendly workflow It doesn't touch the files but stores everything in sidecar files. This approach is extremely great and makes DT compatible with other programs (at least on the common meta-data properties). While it has a database to speed things up, the sidecar files allow you to copy photos around while retaining the manipulations you made with Darktable.
Here is my [import-and-mangle script](http://reidster.net/software/ptp-acquire); it's nothing special, but perhaps useful to look at. The mangling could be extended to include whatever exiftool can get its hands on.
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Yes, it's safe to say there is no such thing (Update: [look at that](https://photo.stackexchange.com/questions/5329/open-source-highly-scriptable-photo-management-platform-for-power-users-like/5339#5339), there might be, but with the level of performance you are asking?). Even [Gimp](http://www.gimp.org/) is not remotely close to Photoshop for advanced users, and the list of features you describe would put such an app in the "advanced" category. This is not true for all apps, Firefox was born after Internet Explorer and is definitely a competitor feature-wise. Photoshop is a monster though, and Adobe has tons of resources to throw at PS and Lightroom to make them the fantastic pieces of software engineering that they are. Moreover, the open source movement has Unix roots, and one old precept of that [philosophy](http://en.wikipedia.org/wiki/Unix_philosophy#Mike_Gancarz:_The_UNIX_Philosophy) is "Small is beautiful. Make each program do one thing well". The [link](http://osp.wikidot.com/the-big-picture) you provided exemplifies it well. There is a ton of small tools that you can use and that can form a chain to get you there, but this is *not* what makes Lightroom or Aperture attractive. The key to these applications is that they were designed by photographers for photographers as one coherent workflow. This lets you do 90% of simple to semi-advanced photo tasks from one single app using the same user interface. This saves people so much time! What I'm getting at is that this week you could get Lightroom for $150. This is *really* cheap for the time it will save you and the power behind that tool. If you are shooting RAW, this is hard to live without. This needs to be put in perspective too: it's half the price of my cheapest lens, and I have 3 lenses next to me that are almost 10 times the cost. I work in the open source business, and this how I've made a living for more than 10 years. We create advanced software (scientific viz, biomedical, supercomputing), but not out of thin air, we have to fund them, we have to pay salaries. The community helps but when it gets pretty sophisticated like this the learning curve can be steep. I don't see any competitor to Lightroom showing up anytime soon just from volunteers working on their free time, *with that level of performance*. Your first request, performance, is key for me here, because if it takes just 30% or 50% more time for me to process one photo, multiply that by 15,000+ pictures a year and the time I wasted completely justify buying a fast commercial app. I've seen open source apps focus on features, some on optimization/performance, rarely both (and I don't blame them). The race for Javascript performance in Firefox is pretty recent, for example. I pick (and support) open source software first, but when I need to get the job done and a tool has a clear lead, I (or my company) will put money to buy a reasonably priced shareware or commercial app. Pragmatism I guess. Now here is something I want to ask you honestly. How far did you use Lightroom? It seems you did, but I'm just asking. You mention that it is not up to what you want, but I'm a bit puzzled here: * It needs to be fast: LR is multi-threaded and uses multiple cores. I throw really big files at it (21MP) and I'm actually amazed its new denoise engine can work so fast. Advanced memory management, multi-threading, image processing, signal processing, you would need some serious fellows to beat that. I'm not saying it can't be faster (it's not GPU accelerated, to my knowledge), but if your app just chokes and page swap after 6MP, I've a problem. * Scriptability, Extensibility: the plugin framework in Lightroom is entirely scriptable. Plugins are scripts (it uses LUA). * Mangle filenames during important, based on camera metadata: LR does a lot of that. I have a precious preset that helps a lot, you can rename files at import by combining patterns and keywords that are replaced by metadata (unfortunately I don't see how to extract a substring of the original filename). See my [answer to another question](https://photo.stackexchange.com/questions/8/how-can-i-organise-my-photos-better/2957#2957) for more info. * Automatically apply EXIF and/or IPTC data during the import automatic importing: again, LR can do that (I apply a ton of info at import time, automatically). * Selecting images with arbitrary queries: you pretty much described Smart Collections in LR. Lot to love here. See my [answer to another question](https://photo.stackexchange.com/questions/4811/good-uses-for-lightrooms-smart-collections/4821#4821) for more info. * Keyboard-based interaction mode: there is a huge list of shortcuts in LR, it's actually a bit overwhelming. For even more flexibility, check [PADDY for Lightroom](http://sites.google.com/site/dorfl68/): free Key mapping, external keyboards, midi controllers, macros. * Ability to identify objects/people in photos: not in LR, but in Aperture I think. * Photo and/or meta-data manipulation on multiple devices: I think the new "Publish" services in LR3 would let you do that (i.e. they are not just "upload", they are more "hey, did that photo change, if yes then I need to push/publish it to other services somewhere").
Here is my [import-and-mangle script](http://reidster.net/software/ptp-acquire); it's nothing special, but perhaps useful to look at. The mangling could be extended to include whatever exiftool can get its hands on.
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Have you taken a look at [Darktable](http://darktable.sourceforge.net/)? It seems to be open-source and Linux-only. Feature description ------------------- ### It needs to be fast It is quite quick and supports computations on the GPU using OpenCL. ### Scriptability It supports scripting using LUA. This is a pretty recent feature (as of '15), so the API is still small. ### Keyboard-based interaction mode You can do quite a few things using the keyboard. You have to check this yourself. ### Extensibility If you can't do it with Lua, you can hack the C code. Well... ### Real-time GUI manipulations Most filters are reasonably quick, so I think yes. ### Ability to identify objects/people in photos Nope ### Photo and/or meta-data manipulation on multiple devices It supports making temporary local copies of images on a remote drive for manipulation (and presumably back-syncing). I'm not using it this way, so I cannot comment much. ### Friendly workflow It doesn't touch the files but stores everything in sidecar files. This approach is extremely great and makes DT compatible with other programs (at least on the common meta-data properties). While it has a database to speed things up, the sidecar files allow you to copy photos around while retaining the manipulations you made with Darktable.
Not a complete answer, but Exiftool is a perl library/command line tool photo metadata reader/writer. Theoretically some of what you want could be scripted with it, especially auto-tagging images and setting file names and directories.
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Have you taken a look at [Darktable](http://darktable.sourceforge.net/)? It seems to be open-source and Linux-only. Feature description ------------------- ### It needs to be fast It is quite quick and supports computations on the GPU using OpenCL. ### Scriptability It supports scripting using LUA. This is a pretty recent feature (as of '15), so the API is still small. ### Keyboard-based interaction mode You can do quite a few things using the keyboard. You have to check this yourself. ### Extensibility If you can't do it with Lua, you can hack the C code. Well... ### Real-time GUI manipulations Most filters are reasonably quick, so I think yes. ### Ability to identify objects/people in photos Nope ### Photo and/or meta-data manipulation on multiple devices It supports making temporary local copies of images on a remote drive for manipulation (and presumably back-syncing). I'm not using it this way, so I cannot comment much. ### Friendly workflow It doesn't touch the files but stores everything in sidecar files. This approach is extremely great and makes DT compatible with other programs (at least on the common meta-data properties). While it has a database to speed things up, the sidecar files allow you to copy photos around while retaining the manipulations you made with Darktable.
Yes, it's safe to say there is no such thing (Update: [look at that](https://photo.stackexchange.com/questions/5329/open-source-highly-scriptable-photo-management-platform-for-power-users-like/5339#5339), there might be, but with the level of performance you are asking?). Even [Gimp](http://www.gimp.org/) is not remotely close to Photoshop for advanced users, and the list of features you describe would put such an app in the "advanced" category. This is not true for all apps, Firefox was born after Internet Explorer and is definitely a competitor feature-wise. Photoshop is a monster though, and Adobe has tons of resources to throw at PS and Lightroom to make them the fantastic pieces of software engineering that they are. Moreover, the open source movement has Unix roots, and one old precept of that [philosophy](http://en.wikipedia.org/wiki/Unix_philosophy#Mike_Gancarz:_The_UNIX_Philosophy) is "Small is beautiful. Make each program do one thing well". The [link](http://osp.wikidot.com/the-big-picture) you provided exemplifies it well. There is a ton of small tools that you can use and that can form a chain to get you there, but this is *not* what makes Lightroom or Aperture attractive. The key to these applications is that they were designed by photographers for photographers as one coherent workflow. This lets you do 90% of simple to semi-advanced photo tasks from one single app using the same user interface. This saves people so much time! What I'm getting at is that this week you could get Lightroom for $150. This is *really* cheap for the time it will save you and the power behind that tool. If you are shooting RAW, this is hard to live without. This needs to be put in perspective too: it's half the price of my cheapest lens, and I have 3 lenses next to me that are almost 10 times the cost. I work in the open source business, and this how I've made a living for more than 10 years. We create advanced software (scientific viz, biomedical, supercomputing), but not out of thin air, we have to fund them, we have to pay salaries. The community helps but when it gets pretty sophisticated like this the learning curve can be steep. I don't see any competitor to Lightroom showing up anytime soon just from volunteers working on their free time, *with that level of performance*. Your first request, performance, is key for me here, because if it takes just 30% or 50% more time for me to process one photo, multiply that by 15,000+ pictures a year and the time I wasted completely justify buying a fast commercial app. I've seen open source apps focus on features, some on optimization/performance, rarely both (and I don't blame them). The race for Javascript performance in Firefox is pretty recent, for example. I pick (and support) open source software first, but when I need to get the job done and a tool has a clear lead, I (or my company) will put money to buy a reasonably priced shareware or commercial app. Pragmatism I guess. Now here is something I want to ask you honestly. How far did you use Lightroom? It seems you did, but I'm just asking. You mention that it is not up to what you want, but I'm a bit puzzled here: * It needs to be fast: LR is multi-threaded and uses multiple cores. I throw really big files at it (21MP) and I'm actually amazed its new denoise engine can work so fast. Advanced memory management, multi-threading, image processing, signal processing, you would need some serious fellows to beat that. I'm not saying it can't be faster (it's not GPU accelerated, to my knowledge), but if your app just chokes and page swap after 6MP, I've a problem. * Scriptability, Extensibility: the plugin framework in Lightroom is entirely scriptable. Plugins are scripts (it uses LUA). * Mangle filenames during important, based on camera metadata: LR does a lot of that. I have a precious preset that helps a lot, you can rename files at import by combining patterns and keywords that are replaced by metadata (unfortunately I don't see how to extract a substring of the original filename). See my [answer to another question](https://photo.stackexchange.com/questions/8/how-can-i-organise-my-photos-better/2957#2957) for more info. * Automatically apply EXIF and/or IPTC data during the import automatic importing: again, LR can do that (I apply a ton of info at import time, automatically). * Selecting images with arbitrary queries: you pretty much described Smart Collections in LR. Lot to love here. See my [answer to another question](https://photo.stackexchange.com/questions/4811/good-uses-for-lightrooms-smart-collections/4821#4821) for more info. * Keyboard-based interaction mode: there is a huge list of shortcuts in LR, it's actually a bit overwhelming. For even more flexibility, check [PADDY for Lightroom](http://sites.google.com/site/dorfl68/): free Key mapping, external keyboards, midi controllers, macros. * Ability to identify objects/people in photos: not in LR, but in Aperture I think. * Photo and/or meta-data manipulation on multiple devices: I think the new "Publish" services in LR3 would let you do that (i.e. they are not just "upload", they are more "hey, did that photo change, if yes then I need to push/publish it to other services somewhere").
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Have you taken a look at [Darktable](http://darktable.sourceforge.net/)? It seems to be open-source and Linux-only. Feature description ------------------- ### It needs to be fast It is quite quick and supports computations on the GPU using OpenCL. ### Scriptability It supports scripting using LUA. This is a pretty recent feature (as of '15), so the API is still small. ### Keyboard-based interaction mode You can do quite a few things using the keyboard. You have to check this yourself. ### Extensibility If you can't do it with Lua, you can hack the C code. Well... ### Real-time GUI manipulations Most filters are reasonably quick, so I think yes. ### Ability to identify objects/people in photos Nope ### Photo and/or meta-data manipulation on multiple devices It supports making temporary local copies of images on a remote drive for manipulation (and presumably back-syncing). I'm not using it this way, so I cannot comment much. ### Friendly workflow It doesn't touch the files but stores everything in sidecar files. This approach is extremely great and makes DT compatible with other programs (at least on the common meta-data properties). While it has a database to speed things up, the sidecar files allow you to copy photos around while retaining the manipulations you made with Darktable.
I would add [DigiKam](https://www.digikam.org/ "digiKam") (KDE photograph management and editing tool) and [LightZone](http://www.lightzoneproject.org/) (editing tool) to the list to examine.
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Wow, that's a long list. I think we can all be pretty safe in saying that there sure isn't anything like that now. One of the most interesting project that shares a lot of your goals is [F-Spot](http://f-spot.org/Goals) -- you might want to look at [getting involved](http://f-spot.org/Get_Involved) there. It's also worth noting that photo management features are on the "long-term roadmap" for the excellent raw converter [RawTherapee](http://www.rawtherapee.com/?mitem=1&artid=55), so that might an interesting place to direct some energy.
I would add [DigiKam](https://www.digikam.org/ "digiKam") (KDE photograph management and editing tool) and [LightZone](http://www.lightzoneproject.org/) (editing tool) to the list to examine.
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Yes, it's safe to say there is no such thing (Update: [look at that](https://photo.stackexchange.com/questions/5329/open-source-highly-scriptable-photo-management-platform-for-power-users-like/5339#5339), there might be, but with the level of performance you are asking?). Even [Gimp](http://www.gimp.org/) is not remotely close to Photoshop for advanced users, and the list of features you describe would put such an app in the "advanced" category. This is not true for all apps, Firefox was born after Internet Explorer and is definitely a competitor feature-wise. Photoshop is a monster though, and Adobe has tons of resources to throw at PS and Lightroom to make them the fantastic pieces of software engineering that they are. Moreover, the open source movement has Unix roots, and one old precept of that [philosophy](http://en.wikipedia.org/wiki/Unix_philosophy#Mike_Gancarz:_The_UNIX_Philosophy) is "Small is beautiful. Make each program do one thing well". The [link](http://osp.wikidot.com/the-big-picture) you provided exemplifies it well. There is a ton of small tools that you can use and that can form a chain to get you there, but this is *not* what makes Lightroom or Aperture attractive. The key to these applications is that they were designed by photographers for photographers as one coherent workflow. This lets you do 90% of simple to semi-advanced photo tasks from one single app using the same user interface. This saves people so much time! What I'm getting at is that this week you could get Lightroom for $150. This is *really* cheap for the time it will save you and the power behind that tool. If you are shooting RAW, this is hard to live without. This needs to be put in perspective too: it's half the price of my cheapest lens, and I have 3 lenses next to me that are almost 10 times the cost. I work in the open source business, and this how I've made a living for more than 10 years. We create advanced software (scientific viz, biomedical, supercomputing), but not out of thin air, we have to fund them, we have to pay salaries. The community helps but when it gets pretty sophisticated like this the learning curve can be steep. I don't see any competitor to Lightroom showing up anytime soon just from volunteers working on their free time, *with that level of performance*. Your first request, performance, is key for me here, because if it takes just 30% or 50% more time for me to process one photo, multiply that by 15,000+ pictures a year and the time I wasted completely justify buying a fast commercial app. I've seen open source apps focus on features, some on optimization/performance, rarely both (and I don't blame them). The race for Javascript performance in Firefox is pretty recent, for example. I pick (and support) open source software first, but when I need to get the job done and a tool has a clear lead, I (or my company) will put money to buy a reasonably priced shareware or commercial app. Pragmatism I guess. Now here is something I want to ask you honestly. How far did you use Lightroom? It seems you did, but I'm just asking. You mention that it is not up to what you want, but I'm a bit puzzled here: * It needs to be fast: LR is multi-threaded and uses multiple cores. I throw really big files at it (21MP) and I'm actually amazed its new denoise engine can work so fast. Advanced memory management, multi-threading, image processing, signal processing, you would need some serious fellows to beat that. I'm not saying it can't be faster (it's not GPU accelerated, to my knowledge), but if your app just chokes and page swap after 6MP, I've a problem. * Scriptability, Extensibility: the plugin framework in Lightroom is entirely scriptable. Plugins are scripts (it uses LUA). * Mangle filenames during important, based on camera metadata: LR does a lot of that. I have a precious preset that helps a lot, you can rename files at import by combining patterns and keywords that are replaced by metadata (unfortunately I don't see how to extract a substring of the original filename). See my [answer to another question](https://photo.stackexchange.com/questions/8/how-can-i-organise-my-photos-better/2957#2957) for more info. * Automatically apply EXIF and/or IPTC data during the import automatic importing: again, LR can do that (I apply a ton of info at import time, automatically). * Selecting images with arbitrary queries: you pretty much described Smart Collections in LR. Lot to love here. See my [answer to another question](https://photo.stackexchange.com/questions/4811/good-uses-for-lightrooms-smart-collections/4821#4821) for more info. * Keyboard-based interaction mode: there is a huge list of shortcuts in LR, it's actually a bit overwhelming. For even more flexibility, check [PADDY for Lightroom](http://sites.google.com/site/dorfl68/): free Key mapping, external keyboards, midi controllers, macros. * Ability to identify objects/people in photos: not in LR, but in Aperture I think. * Photo and/or meta-data manipulation on multiple devices: I think the new "Publish" services in LR3 would let you do that (i.e. they are not just "upload", they are more "hey, did that photo change, if yes then I need to push/publish it to other services somewhere").
I would add [DigiKam](https://www.digikam.org/ "digiKam") (KDE photograph management and editing tool) and [LightZone](http://www.lightzoneproject.org/) (editing tool) to the list to examine.
5,329
Short version of the question: Does anyone know of any good open-source photo management/editing suites, a la [Aperture](http://www.apple.com/aperture/) or [Lightroom](http://www.adobe.com/products/photoshoplightroom/)? I'd want it to run on MacOS X, by the way, though options that are (more or less) cross-platform would certainly be welcome, as long as MacOS X is one of the supported platforms. I know there [is some stuff out there](http://osp.wikidot.com/the-big-picture), but so far, I haven't run into anything that makes me particularly happy. (Though I admit, I've only glanced at some of the available options, and probably done less than that, for others.) Going into a lot more detail (warning: the rest of this post is going to be long. Feel free to skim -- I've made some things bold, to help with that)... There are a bunch of things I'd like to see in such a program. (Some of these may be "in your dreams" type features, but hey, that's in part what this post is about -- finding the software package I've been *dreaming* of. Which Aperture and Lightroom get kind of close to, but not quite there, for various reasons.) (This post was inspired in part by [a question about Lightroom](https://photo.stackexchange.com/questions/4814/lightroom-search-by-aspect-ratio), which seems to highlight a potentially-missing feature.) Such **features might include** (and this is only a subset, I'm sure): * **It needs to be fast** -- Aperture and Lightroom do a decent job (usually) at doing things quickly. This would need to at least get close to their numbers, and preferably beat them. * **Scriptability** -- It'd be really nice to be able to write little scripts to query a set of photos in various ways, and then act upon them -- whether that's to make adjustments, or to do a bulk export, or automatic additions of tags, or whatever. This is really my #1 requirement, I think -- I'm particular about certain things, and currently have scripts that I run pre-import and post-export from Aperture or Lightroom. It'd be nice to have those things integrated in. To define what I'm looking for further, I'd like the ability to do things like: + **mangle filenames during import, based on camera metadata**. (e.g., change `[card]/DCIM/123CANON/IMG_4567.CR2`, shot on my 30D, into something like `[datastore]/2010/11/2010-11-30-some_shoot/my30d-123-4567.CR2`, where `some_shoot` is something I'm prompted to type in during import, and the rest is figured out from the metadata and/or original filename.) + take that `some_shoot` and also **automatically apply EXIF and/or IPTC data during the import** based on it -- and/or other things I'm prompted for (where I can configure what things I want to be prompted for) or have configured (e.g. auto-adding copyright statements, etc.) + **automatic importing** -- doing all the above as soon as I insert a card, or, at my preference (in a setting somewhere), upon a single button-press or whatever. + **selecting images with arbitrary queries** -- something **SQL-Like, perhaps**? Though also different than that -- being able to create, say, a variable that's a collection of images, from which you can make further selections or take other actions. Maybe something like (arbitrarily using [ruby](http://www.ruby-lang.org/)-like syntax for my pseudocode): ``` lowlight = library.search(:iso => 100, :exposure => '< 1/4', :aperture => '> f/16') ``` after which I could then do: ``` thefunstuff = lowlight.search(:rating => '> 3', # 3 stars or better # must have all of these tags: :tags => [ 'beach', 'california' ], # and any one or more of these: :any_tag => [ 'light painting', 'LEDs', 'fire poi' ]) ``` after which I could then do: ``` thefunstuff.add_tag('light painting') # make sure all have this tag thefunstuff.export_to_flickr(:find_set => 'Low Light', :create_set => 'Light Painting on California Beaches') ``` + **changing settings** -- whether I'm working on the `current_photo`, or `thefunstuff` from above, having the ability to change various settings -- whether it's `adjust_exposure(+0.1)`, or `set_whitebalance(5000, -3) # kelvin, tint`, or `photoB.exposure = photoA.exposure` or even: ``` thephotosIwanttweaked.set(photoB.get_settings(:exposure, :whitebalance, :iptc => { :tags, :copyright }) ``` where `thephotosIwanttweaked` is a variable containing a collection of photos previously obtained -- perhaps with a query as shown above, or perhaps via GUI-based selection (click an image, shift-click to select several more, then say `thephotosIwanttweaked = gui.currently_selected_photos` or some such) * **Keyboard-based interaction mode** -- As a programmer in a "past life" (surely obvious from the above), I find that I tend to like to keep my hands on the keyboard a lot of times. GUI and mouse-based (or tablet-based, or what have you) interaction are quite useful when manipulating images, and I want that to exist, too. I just find that typing "select all" at a prompt, or hitting "command-A" on my keyboard, or the like, is far quicker and easier (especially for some kinds of things) than doing it by the GUI. (See the section above about selecting images with arbitrary queries, for example.) Lately, I've been starting to use [emacs](http://www.gnu.org/software/emacs/) for things (after switching from [vim](http://www.vim.org/) -- [editor wars](http://en.wikipedia.org/wiki/Editor_war) aren't allowed here, right? Oh, few of you even know what I'm talking about, huh?). Having the ability to have actual emacs be part of this, and/or to have emacs able to talk to it via an API, would be way cool, in my book. (Of course, this would presumably mean that there'd also/instead be an [elisp](http://en.wikipedia.org/wiki/Emacs_Lisp) way to interact with this, rather than ruby, but whatever. Or maybe [a new language is invented, specific to the purpose](http://www.paulgraham.com/progbot.html). * **Extensibility** -- this thing should have a nice API for writing anything from RAW import tools to fast image editing plugins to exporters for your favorite website. Maybe face detection and such, too? * **Real-time GUI manipulations** -- much like the UIs in Aperture or Lightroom. Along with all the above, the standard GUI-based manipulation strikes me as quite important, too -- having real-time (or close to) feedback when making visual changes is key to visual things. * **Ability to identify objects/people in photos** -- One thing that I think is lacking in Aperture's new face detection stuff, and which could have been really helpful for me recently, is a way to identify ("tag", whatever) people or objects within a photo. Example scenario: I'm shooting a sporting event, and I want to go through and quickly and easily identify which players are in each photo. I imagine me as a human doing a lot of the work on this, though automatic detection would be nifty, too... but the thing that I see as being different from existing UIs is a way to basically select a region of the photo that represents a particular player, and then do so for other players as well, and then go through in a second pass and try to tie them together (with the computer perhaps helping, along the way). So like, maybe I select a player in one photo, and I don't know who they are yet, because their number is obscured... but later, I select what ends up being the same person in another photo, where their number is visible, and then, because of attire or whatever other distinguishing feature there might be, I'm able to tie the two together. But I still don't know their name, necessarily -- but perhaps I have a roster, and that can get looked up. This could also be useful in a variety of other situations, I imagine -- a studio shoot where you want to identify which props were used in which shots, say, so that you can later ask for a photo that includes the such-and-such prop. Stuff like that. Developing a good UI for this would likely be an interesting challenge, but I think I could imagine how it could be done that could make sense. * **Photo and/or meta-data manipulation on multiple devices** -- Maybe the RAW files only exist on one device, or maybe they're on a network drive and can be accessed from multiple computers. But what if, also, previews and metadata were uploaded automatically to a web server somewhere, so that you could get access to them on your smart phone, say, and do ratings, tagging, and the like. The data would get synced up (somehow), and could also potentially be shared to different people -- perhaps (if, say, this was being used at some sort of company) your event coordinator is better at doing the identification tasks, and your photographer is better at post-processing the image itself, and your graphic designer wants input on things, as well. If all those people could access the same images, that could be really really useful. (This could also apply to a photo business, with assistants and such.) Anyway, hopefully that gets the general flavor across of the kinds of things I'd like to do and see, though I'm sure I've only scratched the surface on what's possible, and that even a subset of this stuff would be useful to me. **Does anyone know of anything like this?** Alternately, **would anyone be interested in possibly starting work on such a beast?** I'd need a lot more experience with GUI programming, graphics manipulation, and the like -- not to mention more time and energy to work on this -- before I'd be able to do anything that even begins to be useful on my own... but I think if I had some people to work with, we might be able, together, to do something really really cool. I could imagine forming a company around it, too -- there might well be some hardware that could be useful to integrate with it, which could be the money-making piece. Or it could all just be done as volunteer-done open-source software. Either way. OK, I'm done rambling now. I'm very curious to see what sorts of responses this question will bring. :)
2010/12/01
[ "https://photo.stackexchange.com/questions/5329", "https://photo.stackexchange.com", "https://photo.stackexchange.com/users/2425/" ]
Have you taken a look at [Darktable](http://darktable.sourceforge.net/)? It seems to be open-source and Linux-only. Feature description ------------------- ### It needs to be fast It is quite quick and supports computations on the GPU using OpenCL. ### Scriptability It supports scripting using LUA. This is a pretty recent feature (as of '15), so the API is still small. ### Keyboard-based interaction mode You can do quite a few things using the keyboard. You have to check this yourself. ### Extensibility If you can't do it with Lua, you can hack the C code. Well... ### Real-time GUI manipulations Most filters are reasonably quick, so I think yes. ### Ability to identify objects/people in photos Nope ### Photo and/or meta-data manipulation on multiple devices It supports making temporary local copies of images on a remote drive for manipulation (and presumably back-syncing). I'm not using it this way, so I cannot comment much. ### Friendly workflow It doesn't touch the files but stores everything in sidecar files. This approach is extremely great and makes DT compatible with other programs (at least on the common meta-data properties). While it has a database to speed things up, the sidecar files allow you to copy photos around while retaining the manipulations you made with Darktable.
Darktable (which you can download for OSX [here](http://www.darktable.org/install/#osx)) is probably the software that comes closest to what you are looking for. The workflow still has some rough edges, compared to Lightroom or Aperture, but quite usable especially if you are looking for a scripting interface.
9,995,262
> > **Possible Duplicate:** > > [how to use sql join in mysql](https://stackoverflow.com/questions/9993227/how-to-use-sql-join-in-mysql) > > > table name: tbl\_schedule ``` tr_id(P.K.) mr_id(F.K.) sch_date doctor_id ----------- ----------- -------- ---------- 1 2 01/01/2012 32 2 2 05/01/2012 13 3 4 08/01/2012 14 ``` Table name: tbl\_user ``` mr_id(P.K.) mr_fname mr_lname ----------- ----------- -------- 2 Manish malviya 3 chandan gerry 4 jacky chen 5 raza abbas ``` Please reply with query thanks i want to get number of mr between two dates with `mr_fname, mr_lname group by mr_id` It should look like. in this counting is from tbl\_schedule table and mr\_fnmae and mr\_lname are fetched from tbl\_user with reference of mr\_id. one more thing i dont want 0 count ``` mr_fname mr_lname count ----------- -------- ------- Manish malviya 2 jacky chen 1 ```
2012/04/03
[ "https://Stackoverflow.com/questions/9995262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1180150/" ]
You want to write a `SELECT`: <http://dev.mysql.com/doc/refman/5.0/en/select.html> In your select you are looking to `JOIN` the two tables: <http://dev.mysql.com/doc/refman/5.0/en/join.html> Finally you want to use the `COUNT()`- aggregate function in conjunction with a `GROUP BY` (on user id): <http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html>
``` SELECT mr_fname, mr_lname, COUNT(DISTINCT tr_id) FROM tbl_user INNER JOIN tbl_schedule USING (mr_id) GROUP BY mr_id ```
325,535
Does someone know why the indentation specified in the beginning of the document is lost after the table/figure? How could I fix this? My simplified piece of code is: ``` \documentclass[10pt,a4paper,twoside]{report} \usepackage{caption} \usepackage{pgfplots} \setlength{\parindent}{4em} \begin{document} \chapter{A} \section{B} blabla % not indented because first paragraph blablabla % indented blalablablabla % indented \subsection{C} blblabla % not indented because first paragraph blalalblabla % nicely indented \captionof{table}{caption here} \begin{center} \begin{tabular}{cccc} \hline \textbf{I} & \textbf{S} & \textbf{M} & \textbf{S}\\ \hline A & 0.75 & G & 30\\ B & 1.2 & H & 750\\ C & 15 & I & 2250\\ D & 7.1 & J & 0.4 \\ E & 1300 & K & 0.7\\ & & F & 0-0.2\\ \hline \end{tabular} \end{center} blablablaaablabla % no indentation anymore blalblablabla % and here neither \end{document} ```
2016/08/19
[ "https://tex.stackexchange.com/questions/325535", "https://tex.stackexchange.com", "https://tex.stackexchange.com/users/112333/" ]
It is the command `\captionof` that causes the indentation fail. Try to comment it and the indentation is correct. In the documentation of `caption` it is said that "you should use both `\captionof` and `\captionof*` only inside boxes or environments". There is also given a warning during the compilation. That means you need to put the table inside e.g. a `minipage`. In this case I do not really see the point of not using the floating `table` instead of having it fix in the text. ``` \begin{table}[htb] \centering \caption{caption here} \label{tab:table} \begin{tabular}{cccc} \hline \textbf{I} & \textbf{S} & \textbf{M} & \textbf{S}\\ \hline A & 0.75 & G & 30\\ B & 1.2 & H & 750\\ C & 15 & I & 2250\\ D & 7.1 & J & 0.4 \\ E & 1300 & K & 0.7\\ & & F & 0-0.2\\ \hline \end{tabular} \end{table} ```
I guess you're doing ``` \captionof{table}{caption here} \begin{center} \begin{tabular}{cccc} ``` in order to get some vertical space between the caption and the table, but this is wrong: `\captionof` should be in the same environment as the table. In order to get the vertical spacing, issue ``` \captionsetup{position=above} ``` Example: ``` \documentclass[10pt,a4paper,twoside]{report} \usepackage{caption} \setlength{\parindent}{4em} \begin{document} \chapter{A} \section{B} blabla % not indented because first paragraph blablabla % indented blalablablabla % indented \subsection{C} blblabla % not indented because first paragraph blalalblabla % nicely indented \begin{center} \captionsetup{position=above} \captionof{table}{caption here} \begin{tabular}{cccc} \hline \textbf{I} & \textbf{S} & \textbf{M} & \textbf{S}\\ \hline A & 0.75 & G & 30\\ B & 1.2 & H & 750\\ C & 15 & I & 2250\\ D & 7.1 & J & 0.4 \\ E & 1300 & K & 0.7\\ & & F & 0-0.2\\ \hline \end{tabular} \end{center} blablablaaablabla % indented blalblablabla % indented \end{document} ``` [![enter image description here](https://i.stack.imgur.com/7a6Rl.png)](https://i.stack.imgur.com/7a6Rl.png) However, you should use the `table` environment with the regular `\caption`, rather than `center` and `\captionof`: you're going to have several page breaking related problems, if you want “here” tables and figures.
64,178,441
I was trying to clean "NaN" variables in a given array example; My input array A is: ``` float A[] = { 5.0f, NAN, 1.5f, 0.0f, 1.75f }; ``` Expected output array A is: ``` {5.0f,1.5f, 0.0f, 1.75f} ``` I can delete each NAN and shift the elements one time to left. But if the array is too big to handle, it will become inefficient algorithm. I couldn't find any solution in C. So my question is there any more efficient solution than these approach? Regards.
2020/10/02
[ "https://Stackoverflow.com/questions/64178441", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14382172/" ]
There is an `O(n)` solution using [two pointers technique](https://leetcode.com/articles/two-pointer-technique/?page=1#). It's posible to swap all `NaN` terms to the end of the array while preserving relative ordering of non `NaN` terms. `p` keeps the record of how many non `NaN` terms are encountered and its returned to keep track of current size of `A`. ```c int moveNAN(float A[], int n) { int p = 0; for(int i = 0; i < n; ++i) if(!isnan(A[i])) // if `isnan` is not defined use `A[i] == A[i]` (NaN values return false) { if(p != i) swap(A[i], A[p]); ++p; } return p; } ```
> > Eliminating NaN Values from an array in C > > > There is little special here about NaN. To eliminate a value from an array, walk the array. ``` // `isnan()` #include <math.h> // In place solution float A[] = { 5.0f, NAN, 1.5f, 0.0f, 1.75f }; size_t n = sizeof A/sizeof A[0]; size_t w = 0; for (size_t r = 0; r < n; r++) { if (!isnan(A[r]) { A[w++] = A[r]; } } // Array size is still `n`, yet the first `w` elements are of interest. ``` To make a new array, code could form a VLA and walk `A[]` twice, first to determine size, 2nd to read and copy. ``` // New array solution float A[] = { 5.0f, NAN, 1.5f, 0.0f, 1.75f }; size_t n = sizeof A/sizeof A[0]; size_t new_n = 0; for (size_t r = 0; r < n; r++) { if (!isnan(A[r]) new_n++; } if (new_n == 0) TBD_code(); // VLA must be at least 1 float new_A[new_n]; size_t w = 0; for (size_t r = 0; r < n; r++) { if (!isnan(A[r]) { new_A[w++] = A[r]; } } ```
55,209,914
I am trying to do a very simple calculation of `11.000 + 5.000` expecting to have `16.000` then dividing it by `2` expecting to get a final result of `8.000`. It was working ok in another language (ahk) but I'm having unexpected results trying it in javascript (Not a Number, 5.5 and 5.50025) **How should I write this calculation to get the expected result of 8.000?** ```js var A = "11.000"; var B = "5.000"; //1st try var resultA = (A + B) / 2; alert(resultA); //2nd try var resultB = parseInt(A + B) / 2; alert(resultB); //3nd try var resultC = parseFloat(A + B) / 2; alert(resultC); //expected = 8.000 ```
2019/03/17
[ "https://Stackoverflow.com/questions/55209914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5875416/" ]
Here `A + B` is doing actually string concationation not simple addition. you need to change them to number first ```js var A = "11.000"; var B = "5.000"; var resultA = ((+A) + (+B)) / 2; console.log(resultA); // You can use toFixed if you three decimal digit console.log(resultA.toFixed(3)); ```
Here A and B are in string format and Once you do A + B the result will be "11.000" + "5.000" = "11.0005.000" (string concatenation). So to get expected result you should parse each string value to Float/Int then do the addition operation. Try, `var resultD = (parseFloat(A) + parseFloat(B)) /2`
55,209,914
I am trying to do a very simple calculation of `11.000 + 5.000` expecting to have `16.000` then dividing it by `2` expecting to get a final result of `8.000`. It was working ok in another language (ahk) but I'm having unexpected results trying it in javascript (Not a Number, 5.5 and 5.50025) **How should I write this calculation to get the expected result of 8.000?** ```js var A = "11.000"; var B = "5.000"; //1st try var resultA = (A + B) / 2; alert(resultA); //2nd try var resultB = parseInt(A + B) / 2; alert(resultB); //3nd try var resultC = parseFloat(A + B) / 2; alert(resultC); //expected = 8.000 ```
2019/03/17
[ "https://Stackoverflow.com/questions/55209914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5875416/" ]
Here `A + B` is doing actually string concationation not simple addition. you need to change them to number first ```js var A = "11.000"; var B = "5.000"; var resultA = ((+A) + (+B)) / 2; console.log(resultA); // You can use toFixed if you three decimal digit console.log(resultA.toFixed(3)); ```
Just remove the quotation marks and the vars will be recognized as number not as string so you'll get the expected result. ```js var A = 11.000; var B = 5.000; //1st try var resultA = (A + B) / 2; alert(resultA); //2nd try var resultB = parseInt(A + B) / 2; alert(resultB); //3nd try var resultC = parseFloat(A + B) / 2; alert(resultC); //expected = 8.000 ```
55,209,914
I am trying to do a very simple calculation of `11.000 + 5.000` expecting to have `16.000` then dividing it by `2` expecting to get a final result of `8.000`. It was working ok in another language (ahk) but I'm having unexpected results trying it in javascript (Not a Number, 5.5 and 5.50025) **How should I write this calculation to get the expected result of 8.000?** ```js var A = "11.000"; var B = "5.000"; //1st try var resultA = (A + B) / 2; alert(resultA); //2nd try var resultB = parseInt(A + B) / 2; alert(resultB); //3nd try var resultC = parseFloat(A + B) / 2; alert(resultC); //expected = 8.000 ```
2019/03/17
[ "https://Stackoverflow.com/questions/55209914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5875416/" ]
Here A and B are in string format and Once you do A + B the result will be "11.000" + "5.000" = "11.0005.000" (string concatenation). So to get expected result you should parse each string value to Float/Int then do the addition operation. Try, `var resultD = (parseFloat(A) + parseFloat(B)) /2`
Just remove the quotation marks and the vars will be recognized as number not as string so you'll get the expected result. ```js var A = 11.000; var B = 5.000; //1st try var resultA = (A + B) / 2; alert(resultA); //2nd try var resultB = parseInt(A + B) / 2; alert(resultB); //3nd try var resultC = parseFloat(A + B) / 2; alert(resultC); //expected = 8.000 ```
29,076,024
I have managed to disable a set of text boxes using "disabled" tag. but I want all the text boxes enabled using a on-click in button. I tried this but it doesn't work. ``` $(document).ready(function(){ $('#btnSaveGenInfo').click(function(){ $('#textfieldToClose').prop('disabled', false) }); }); ```
2015/03/16
[ "https://Stackoverflow.com/questions/29076024", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
> > "True/False: The Java interpreter converts files from a byte-code format to executable files". > > > The answer is false1. The Java interpreter is one of the two components of the JVM that is responsible for executing Java code. It does it by "emulating" the execution of the Java Virtual Machine instructions (bytecodes); i.e. by pretending to be a "real" instance of the virtual machine. The other JVM component that is involved is the Just In Time (JIT) compiler. This identifies Java methods that have been interpreted for a significant amount of time, and does an on-the-fly compilation to native code. This native code is then executed instead of interpreting the bytecodes. But the JIT compiler does not write the compiled native code to the file system. Instead it writes it directly into a memory segment ready to be executed. --- Java's interpret / JIT compile is more complicated, but it has a couple of advantages: * It means that it is not necessary to compile bytecodes to native code before the application can be run, which removes a significant impediment to portability. * It allows the JVM to gather runtime statistics on how the application is functioning, which can give hints as to the best way to optimize the native code. The result is faster execution for long-running applications. The downside is that JIT compilation is one of the factors that tends to make Java applications slow to start (compared with C / C++ for example). --- 1 - ... for mainstream Java (tm) compilers. Android isn't Java (tm)2. Note that the first version of Java was interpreter only. I have also seen Java (not tm) implementations where the native code compilers were either ahead-of-time or eager ... or a combination of both. 2 - You are only permitted by Oracle to describe your "java-like" implementation as Java(tm) if it passes the Java compliance tests. Android wouldn't.
The Java compiler converts the source code to bytecode. This bytecode is then interpreted (or just-in-time-compiled and then executed) by the JVM. This bytecode is a kind of [intermediate language](http://en.wikipedia.org/wiki/Intermediate_language) that has not platform dependence. The virtual machine then is the layer that provides system specific functionality. It is also possible to compile Java code to native code, a project aiming this is for example the [GCJ](http://de.wikipedia.org/wiki/GNU_Compiler_for_Java). To answer your question: no, a normal Java compiler does not emit an executable binary, but a set of classes that can be executed using a JVM. You can read more about this on [Wikipedia](http://en.wikipedia.org/wiki/Java_(programming_language)).
29,076,024
I have managed to disable a set of text boxes using "disabled" tag. but I want all the text boxes enabled using a on-click in button. I tried this but it doesn't work. ``` $(document).ready(function(){ $('#btnSaveGenInfo').click(function(){ $('#textfieldToClose').prop('disabled', false) }); }); ```
2015/03/16
[ "https://Stackoverflow.com/questions/29076024", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
> > "True/False: The Java interpreter converts files from a byte-code format to executable files". > > > The answer is false1. The Java interpreter is one of the two components of the JVM that is responsible for executing Java code. It does it by "emulating" the execution of the Java Virtual Machine instructions (bytecodes); i.e. by pretending to be a "real" instance of the virtual machine. The other JVM component that is involved is the Just In Time (JIT) compiler. This identifies Java methods that have been interpreted for a significant amount of time, and does an on-the-fly compilation to native code. This native code is then executed instead of interpreting the bytecodes. But the JIT compiler does not write the compiled native code to the file system. Instead it writes it directly into a memory segment ready to be executed. --- Java's interpret / JIT compile is more complicated, but it has a couple of advantages: * It means that it is not necessary to compile bytecodes to native code before the application can be run, which removes a significant impediment to portability. * It allows the JVM to gather runtime statistics on how the application is functioning, which can give hints as to the best way to optimize the native code. The result is faster execution for long-running applications. The downside is that JIT compilation is one of the factors that tends to make Java applications slow to start (compared with C / C++ for example). --- 1 - ... for mainstream Java (tm) compilers. Android isn't Java (tm)2. Note that the first version of Java was interpreter only. I have also seen Java (not tm) implementations where the native code compilers were either ahead-of-time or eager ... or a combination of both. 2 - You are only permitted by Oracle to describe your "java-like" implementation as Java(tm) if it passes the Java compliance tests. Android wouldn't.
The answer is `false` **reason**: `JIT-just in time compiler` and `java interpreter` does a same thing in different way but as per performance JIT wins. The main task is to convert the given `bytecode` into machine dependent `Assembly language` as of abstract information.`Assembly level language` is a low level language which understood by machine's assembler and after that assembler converts it to `01010111`.....
29,076,024
I have managed to disable a set of text boxes using "disabled" tag. but I want all the text boxes enabled using a on-click in button. I tried this but it doesn't work. ``` $(document).ready(function(){ $('#btnSaveGenInfo').click(function(){ $('#textfieldToClose').prop('disabled', false) }); }); ```
2015/03/16
[ "https://Stackoverflow.com/questions/29076024", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
> > "True/False: The Java interpreter converts files from a byte-code format to executable files". > > > The answer is false1. The Java interpreter is one of the two components of the JVM that is responsible for executing Java code. It does it by "emulating" the execution of the Java Virtual Machine instructions (bytecodes); i.e. by pretending to be a "real" instance of the virtual machine. The other JVM component that is involved is the Just In Time (JIT) compiler. This identifies Java methods that have been interpreted for a significant amount of time, and does an on-the-fly compilation to native code. This native code is then executed instead of interpreting the bytecodes. But the JIT compiler does not write the compiled native code to the file system. Instead it writes it directly into a memory segment ready to be executed. --- Java's interpret / JIT compile is more complicated, but it has a couple of advantages: * It means that it is not necessary to compile bytecodes to native code before the application can be run, which removes a significant impediment to portability. * It allows the JVM to gather runtime statistics on how the application is functioning, which can give hints as to the best way to optimize the native code. The result is faster execution for long-running applications. The downside is that JIT compilation is one of the factors that tends to make Java applications slow to start (compared with C / C++ for example). --- 1 - ... for mainstream Java (tm) compilers. Android isn't Java (tm)2. Note that the first version of Java was interpreter only. I have also seen Java (not tm) implementations where the native code compilers were either ahead-of-time or eager ... or a combination of both. 2 - You are only permitted by Oracle to describe your "java-like" implementation as Java(tm) if it passes the Java compliance tests. Android wouldn't.
False for regular JVMs. No executable files are created. The conversion from bytecode to native code for that platform takes place on the fly during execution. If the program is stopped, the compiled code is gone (was in memory only). The new Android JVM ART does compile the bytecode into executables before to have better startup and runtime behavior. So ART creates files. > > ART straddles an interesting mid-ground between compiled and interpreted code, called ahead-of-time (AOT) compilation. Currently with Android apps, they are interpreted at runtime (using the JIT), every time you open them up. This is slow. (iOS apps, by comparison, are compiled native code, which is much faster.) With ART enabled, each Android app is compiled to native code when you install it. Then, when it’s time to run the app, it performs with all the alacrity of a native app. <http://www.extremetech.com/computing/170677-android-art-google-finally-moves-to-replace-dalvik-to-boost-performance-and-battery-life> > > >
40,571,363
I have a MySQL table with 6 columns. Some of the columns contain long JSON strings that have newlines and spaces. When I list the content of the table with the SELECT statement, the output is very messy. Is there a command (or default setting I can change), to limit the output of each column to the first few meaningful characters, so that each row will show as single line regardless of the cell content? Something like: ``` +---------------------------+-------------------------+---------+-----------+--------------+----------+ | jsondata | column2 | column3 | column4 | column5 | column6 | +---------------------------+-------------------------+---------+-----------+--------------+----------+ | { "Text":[{"user_id":"3","| ABCDEFABCDEFABCDEFABC | 3 | ABCABCA | txt | { "email"| +---------------------------+-------------------------+---------+-----------+--------------+----------+ ```
2016/11/13
[ "https://Stackoverflow.com/questions/40571363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7147892/" ]
You need to replace `L == int` and `L == str` (which will be always valuated to False) with the folowing: ``` all(isinstance(item, str) for item in L) # L == str all(isinstance(item, int) for item in L) # L == int ```
You can try this: Have a function that checks if the elements inside is a number or a string. ``` def isNumber(s): # Helper function to check if it is a Number or a string try: float(s) return True except ValueError: return False def find_index_of_min(L): """ Parameter: a list L Returns: the index of the minimum element of the list (returns None if the list is empty) """ if L == []: return None elif isNumber(L[0]): min = float('inf') for i in range(len(L)): if L[i] < min: min = L[i] min_index = i return min_index else: min = 'Z' for i in range(len(L)): if L[i] < min: min = L[i] min_index = i return min_index import sys import math def main(): """ Read and print a file's contents. """ # filename = str(input('Name of input file: ')) # string = readfile(filename) # print() # print('The original list of cities is:') # for i in range(len(string)): # print(i, ':', string[i], sep="") print(find_index_of_min([])) print(find_index_of_min([3, 2, 1, 0])) print(find_index_of_min(['A', 'Z', 'Y', 'B'])) print(find_index_of_min(['B', 'A', 'Z', 'Y'])) main() ```
24,079,203
I want to use *Universal Image Loader* library in my project I am using `ImageLoader` but it's not working well. I have to use for grid view and User Profile Image. My `ImageLoader` is not working and is giving me a size problem. Please tell me how to use Univarsel Library in my project . here Is my Activity For Profile ``` // ImageLoader class instance ImageLoader imgLoader = new ImageLoader(getApplicationContext(), Welcome.this); image.setTag(image_url); // whenever you want to load an image from url // call DisplayImage function // url - image url to load // loader - loader image, will be displayed before getting image // image - ImageView imgLoader.DisplayImage(image_url, Welcome.this, image); ``` Above code used In my profile activity. I want to know if I am adding Univarsal Image Loader Library. What code I have to use to load image from url?
2014/06/06
[ "https://Stackoverflow.com/questions/24079203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3709878/" ]
As far as I know, you **can't** use prepared statements nor bind values with Joomla. If you read the Secure Coding Guideliness from the Joomla documentation (<http://docs.joomla.org/Secure_coding_guidelines#Constructing_SQL_queries>), they don't talk about prepared statements, only about using casting or quoting to avoid SQL injection.
In Joomla there is normally the `check()`, `bind()`, `store()` triple from JTable that prevents injection. `JDatabaseQueryPreparable` has a bind method that you may want to look at. You may also want to look at the docblocks for `JDatabaseQueryLimitable`. One thing I would suggest is that when you get that error, usually it is really because you do have a problem in your query (often wrong quoting or something being empty that needs not to be empty. To see your generated query you an use `echo $query->dump();` and then try running it directly in sql. Also in general it's wise to use `$db->quote()` and `$db->quoteName()` if you are using the API that way you won't run into quoting problems. I think you may have a quoting problem but it's hard to know without knowing your field names.
24,079,203
I want to use *Universal Image Loader* library in my project I am using `ImageLoader` but it's not working well. I have to use for grid view and User Profile Image. My `ImageLoader` is not working and is giving me a size problem. Please tell me how to use Univarsel Library in my project . here Is my Activity For Profile ``` // ImageLoader class instance ImageLoader imgLoader = new ImageLoader(getApplicationContext(), Welcome.this); image.setTag(image_url); // whenever you want to load an image from url // call DisplayImage function // url - image url to load // loader - loader image, will be displayed before getting image // image - ImageView imgLoader.DisplayImage(image_url, Welcome.this, image); ``` Above code used In my profile activity. I want to know if I am adding Univarsal Image Loader Library. What code I have to use to load image from url?
2014/06/06
[ "https://Stackoverflow.com/questions/24079203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3709878/" ]
As far as I know, you **can't** use prepared statements nor bind values with Joomla. If you read the Secure Coding Guideliness from the Joomla documentation (<http://docs.joomla.org/Secure_coding_guidelines#Constructing_SQL_queries>), they don't talk about prepared statements, only about using casting or quoting to avoid SQL injection.
From Joomla4, binding data to named parameters is possible with the `bind()` method. This has been asked for for many years and finally it has come to the CMS. * Early reference in Joomla Docs: <https://docs.joomla.org/J4.x:Moving_Joomla_To_Prepared_Statements> * Proper Joomla Documenation: <https://docs.joomla.org/J4.x:Selecting_data_using_JDatabase> * Here's a good tutorial: <https://www.techfry.com/joomla/prepared-statements-in-joomla-4> The syntax is precisely as prophecized in the snippet in the post ``` $taste = "sweet"; $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select("*") ->from($db->quoteName("food")) ->where($db->quoteName("taste") . " = :taste") ->bind(":taste", $taste); $db->setQuery($query); $rows = $db->loadAssocList(); ```
48,069,223
I am trying to compare between two tables and test the results using Gherkin but I don't know how to make it declare two lists in the @when section instead of one, like how it is shown below: ``` @When("^the integer table :$") public void the_integer_table_(List<Integer> comp1, List<Integer> comp2) { for(int i = 0; i < comp1.size(); i++) { compare[i] = comp1.get(i); } for(int i = 0; i < comp2.size(); i++) { compare2[i] = comp1.get(i); } comparer.comparer_tableau( compare, compare2); } ``` Here is my .feature file: ``` Scenario: Compare the elements of two tables and return a boolean table as a result Given I am starting a comparision operation When these two integer table are entered : |1|2|3|4|5| |0|2|5|4|5| Then I should see the correct answer is: |false|true|false|true|true| ``` Here is what I get when I run it: ``` @When("^these two integer table two are entered :$") public void these_two_integer_table_two_are_entered_(DataTable arg1) { } ``` P.S: I did try and look for solutions but didn't find any.
2018/01/02
[ "https://Stackoverflow.com/questions/48069223", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7138725/" ]
Untested but should do what you want: ``` Private Sub Worksheet_Calculate() Const MAIN_WS_NAME As String = "PDP Base" 'use a constant for fixed values Dim ws As Worksheet, mainws As Worksheet, wb As Workbook Dim x As Long, y As Long 'Long not Single Dim tVar As Double Set wb = ActiveWorkbook Set mainws = wb.Worksheets(MAIN_WS_NAME) For y = 2 To 4 For x = 29 To 43 tVar = 0 For Each ws In wb.Worksheets If ws.Name Like MAIN_WS_NAME & "*" And ws.Name <> MAIN_WS_NAME Then tVar = tVar + ws.Cells(x, y).Value End If Next ws mainws.Cells(x, y).Value = tVar Next x Next y End Sub ```
Its been a bit since I posted the original question, but I've gotten much further since then and just wanted to post my progress for others to use incase they need something similar. There is still a lot of cleaning that could be done, and its not finished, but the basic idea works really *really* well. The code takes several **codenamed** (not tab names; allows users to change the tab name to something different) main sheets and loops through each, adding formulas that dynamically add cells from similarly named subsheets into the main sheet across multiple blocks of cells. Also wanted to thank the original answer again provided by Tim Williams as that helped me tremendously to get going in the right direction and is the foundation to the code below. **Use at your own risk.** I hear CodeNames and using VBProject type of codes can give you a bad day if they break. Main Code Below ``` Public Sub Sheet_Initilization() Dim ws As Worksheet, mainws As Worksheet, wb As Workbook Dim codename As String Dim mainwsname As String Set wb = ActiveWorkbook 'block code to run code smoother Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Application.EnableEvents = False 'PLACEHOLDER FOR LATER USE CaseNames = Array("PDPBase", "PDPSens", "PBPBase", "PBPSens", "PNPBase", "PNPSens", "PUDBase", "PUDSens") CaseNames = Array("PDPBase", "PBPBase", "PNPBase", "PUDBase") 'main 4 cases, more to come For Each c In CaseNames 'cycle through each "Main" case sheet codename = c Set mainws = wb.Sheets(CN(wb, codename)) 'calls function to retrieve code name of the main case sheet 'allows users to change main case tab names without messing up the codes 'must change security settings to use, looking into alternatives mainwsname = mainws.Name 'probably could do without with some optimization For Each b In Range("InputAdditionCells").Cells 'uses named range of multiple blocks of cells, B29:D34 M29:O43 I53:J68 for example 'cycles through each cell in every block mainws.Range(b.Address).Formula = "=" 'initial formula For Each ws In wb.Worksheets 'cycles through each sheet If ws.Name Like mainwsname & "*" And ws.Name <> mainwsname Then 'finds similarily named sub sheets (PDP Base 1, PDP Base 2...etc) ', but won't use the main sheet (PDP Base) If b.Address Like "$Y*" Then 'special column to use different offset formula mainws.Range(b.Address).Formula = mainws.Range(b.Address).Formula & "+'" & ws.Name & "'!" & b.Offset(0, 4).Address Else mainws.Range(b.Address).Formula = mainws.Range(b.Address).Formula & "+'" & ws.Name & "'!" & b.Address End If End If Next ws Next b For Each d In Range("InputWeightedCells").Cells 'same idea as before, different main formula (weighted average) mainws.Range(d.Address).Formula = "=" For Each ws In wb.Worksheets If ws.Name Like mainwsname & "*" And ws.Name <> mainwsname Then If d.Address Like "*$68" Then 'special row to use different offset formula mainws.Range(d.Address).Formula = mainws.Range(d.Address).Formula & "+('" & ws.Name & "'!" & d.Address _ & "*'" & ws.Name & "'!" & d.Offset(-21, 23).Address & ")" Else mainws.Range(d.Address).Formula = mainws.Range(d.Address).Formula & "+('" & ws.Name & "'!" & d.Address _ & "*'" & ws.Name & "'!" & d.Offset(-24, 23).Address & ")" End If End If Next ws Next d MsgBox (mainwsname) 'DELETE; makes sure code is running properly/codebreak without using the break feature Next c 'reactivate original block code Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic Application.EnableEvents = True End Sub 'cool beans ``` Function that's called (need to change the Macro settings in the trust center settings from excel options to run). Once again use at your own risk. ``` Function CN(wb As Workbook, codename As String) As String CN = wb.VBProject.VBComponents(codename).Properties("Name").Value End Function ```
42,209,594
Why if I give those command lines: ``` ip rule add from 10.222.192.0/25 table pdl ip route add 10.104.44.0/24 via 10.222.193.17 table pdl ``` everything works, while if I execute this script: ``` #!/bin/sh IPRULEADD=$(/sbin/ip rule add) IPROUTEADD=$(/sbin/ip route add) # # #----------- pdl --------------------------- echo 100 pdl >> /etc/iproute2/rt_tables $IPRULEADD from 10.222.192.0/25 table pdl $IPROUTEADD 10.104.44.0/24 via 10.222.193.17 table pdl ``` I get this error: `from: can't read /var/mail/10.222.192.0/25` ? Thanks
2017/02/13
[ "https://Stackoverflow.com/questions/42209594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7558870/" ]
You can either `export` it on server.js or make it a `global` or pass it as a parameter. ``` export app; import { app } from './server'; ``` or ``` global.app = app; ``` or: ``` app.use('/login', login(app)); ``` login.js ``` function(app) { // login stuff here } ```
In your server.js just use `require('login')(app);` In your login.js:- ``` module.exports = function (app) { app.get('/', function(req, res) { res.render('login.jade'); }); }; ```
42,209,594
Why if I give those command lines: ``` ip rule add from 10.222.192.0/25 table pdl ip route add 10.104.44.0/24 via 10.222.193.17 table pdl ``` everything works, while if I execute this script: ``` #!/bin/sh IPRULEADD=$(/sbin/ip rule add) IPROUTEADD=$(/sbin/ip route add) # # #----------- pdl --------------------------- echo 100 pdl >> /etc/iproute2/rt_tables $IPRULEADD from 10.222.192.0/25 table pdl $IPROUTEADD 10.104.44.0/24 via 10.222.193.17 table pdl ``` I get this error: `from: can't read /var/mail/10.222.192.0/25` ? Thanks
2017/02/13
[ "https://Stackoverflow.com/questions/42209594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7558870/" ]
in ES6(ecmascript6): ``` server.js export const app = express() login.js import { app } from '../server' ``` in ES5: ``` server.js module.exports: { app: express() } login.js var app = require('path').app ```
In your server.js just use `require('login')(app);` In your login.js:- ``` module.exports = function (app) { app.get('/', function(req, res) { res.render('login.jade'); }); }; ```
73,628,868
###### Updated Let's suppose that you got octal escape sequences in a stream: ``` backslash \134 is escaped as \134134 single quote ' and double quote \042 linefeed `\012` and carriage return `\015` %s & etc... ``` **note:** The escaped characters are limited to `0x01-0x1F 0x22 0x5C 0x7F` How can you revert those escape sequences back to their corresponding character with `awk`? While `awk` is able to understand them out-of-box when used in a literal string or as a parameter argument, I can't find the way to leverage this capability when the escape sequence is part of the data. For now I'm using one `gsub` per escape sequence but it doesn't feel efficient. Here's the expected output for the given sample: ``` backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` **PS:** While I have the additional constraint of unescaping each line into an awk variable before printing the result, it doesn't really matter.
2022/09/07
[ "https://Stackoverflow.com/questions/73628868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3387716/" ]
Using GNU awk for `strtonum()` and lots of meaningfully-named variables to show what each step does: ``` $ cat tst.awk function octs2chars(str, head,tail,oct,dec,char) { head = "" tail = str while ( match(tail,/\\[0-7]{3}/) ) { oct = substr(tail,RSTART+1,RLENGTH-1) dec = strtonum(0 oct) char = sprintf("%c", dec) head = head substr(tail,1,RSTART-1) char tail = substr(tail,RSTART+RLENGTH) } return head tail } { print octs2chars($0) } ``` ``` $ awk -f tst.awk file backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` If you don't have GNU awk then write a small function to convert octal to decimal, e.g. `oct2dec()` below, and then call that instead of `strtonum()`: ``` $ cat tst2.awk function oct2dec(oct, dec) { dec = substr(oct,1,1) * 8 * 8 dec += substr(oct,2,1) * 8 dec += substr(oct,3,1) return dec } function octs2chars(str, head,tail,oct,dec,char) { head = "" tail = str while ( match(tail,/\\[0-7]{3}/) ) { oct = substr(tail,RSTART+1,RLENGTH-1) dec = oct2dec(oct) # replaced "strtonum(0 oct)" char = sprintf("%c", dec) head = head substr(tail,1,RSTART-1) char tail = substr(tail,RSTART+RLENGTH) } return head tail } { print octs2chars($0) } ``` ``` $ awk -f tst2.awk file backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` The above assumes that, [as discussed in comments](https://stackoverflow.com/questions/73628868/decoding-octal-escape-sequences-in-input-with-awk?noredirect=1#comment130038302_73628868), the only backslashes in the input will be in the context of the start of octal numbers as shown in the provided sample input.
With `GNU awk` which supports `strtonum()` function, would you please try: ``` awk '{ while (match($0, /\\[0-7]{1,3}/)) { printf("%s", substr($0, 1, RSTART - 1)) # print the substring before the match printf("%c", strtonum("0" substr($0, RSTART + 1, RLENGTH))) # convert the octal string to character $0 = substr($0, RSTART + RLENGTH) # update $0 with remaining substring } print }' input_file ``` * It processes the matched substring (octal presentation) in the `while` loop one by one. * `substr($0, RSTART + 1, RLENGTH)` skips the leading backslash. * `"0"` prepended to `substr` makes an octal string. * `strtonum()` converts the octal string to the numeric value. * The final `print` outputs the remaining substring.
73,628,868
###### Updated Let's suppose that you got octal escape sequences in a stream: ``` backslash \134 is escaped as \134134 single quote ' and double quote \042 linefeed `\012` and carriage return `\015` %s & etc... ``` **note:** The escaped characters are limited to `0x01-0x1F 0x22 0x5C 0x7F` How can you revert those escape sequences back to their corresponding character with `awk`? While `awk` is able to understand them out-of-box when used in a literal string or as a parameter argument, I can't find the way to leverage this capability when the escape sequence is part of the data. For now I'm using one `gsub` per escape sequence but it doesn't feel efficient. Here's the expected output for the given sample: ``` backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` **PS:** While I have the additional constraint of unescaping each line into an awk variable before printing the result, it doesn't really matter.
2022/09/07
[ "https://Stackoverflow.com/questions/73628868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3387716/" ]
With `GNU awk` which supports `strtonum()` function, would you please try: ``` awk '{ while (match($0, /\\[0-7]{1,3}/)) { printf("%s", substr($0, 1, RSTART - 1)) # print the substring before the match printf("%c", strtonum("0" substr($0, RSTART + 1, RLENGTH))) # convert the octal string to character $0 = substr($0, RSTART + RLENGTH) # update $0 with remaining substring } print }' input_file ``` * It processes the matched substring (octal presentation) in the `while` loop one by one. * `substr($0, RSTART + 1, RLENGTH)` skips the leading backslash. * `"0"` prepended to `substr` makes an octal string. * `strtonum()` converts the octal string to the numeric value. * The final `print` outputs the remaining substring.
this separate post is made specifically to showcase how to extend the octal lookup reference tables in `gawk` `unicode`-mode to ***`all 256 bytes`*** without external dependencies or warning messages: * `ASCII` bytes reside in table `o2bL` * 8-bit bytes reside in table `o2bH` . ``` # gawk profile, created Fri Sep 16 09:53:26 2022 'BEGIN { 1 makeOctalRefTables(PROCINFO["sorted_in"] = "@val_str_asc" \ (ORS = "")) 128 for (_ in o2bL) { 128 print o2bL[_] } 128 for (_ in o2bH) { 128 print o2bH[_] } } function makeOctalRefTables(_,__,___,____) { 1 _=__=___=____="" for (_ in o2bL) { break } 1 if (!(_ in o2bL)) { 1 ____=_+=((_+=_^=_<_)-+-++_)^_-- 128 do { o2bL[sprintf("\\%o",_)] = \ sprintf("""%c",_) } while (_--) 1 o2bL["\\" ((_+=(_+=_^=_<_)+_)*_--+_+_)] = "\\&" 1 ___=--_*_^_--*--_*++_^_*(_^=++_)^(! —_) 128 do { o2bH[sprintf("\\%o", +_)] = \ sprintf("%c",___+_) } while (____<--_) } 1 return length(o2bL) ":" length(o2bH) }' ``` | ``` \0 \1 \2 \3 \4 \5 \6 \7 \10\11 \12 \13 \14 \16 \17 \20 \21 \22 \23 \24 \25 \26 \27 \30 \31 \32 \33 34 \35 \36 \37 \40 \41 !\42 "\43 #\44 $\45 %\47 '\50 (\51 )\52 *\53 +\54 ,\55 -\56 .\57 / \60 0\61 1\62 2\63 3\64 4\65 5\66 6\67 7\70 8\71 9\72 :\73 ;\74 <\75 =\76 >\77 ? \100 @\101 A\102 B\103 C\104 D\105 E\106 F\107 G\110 H\111 I\112 J\113 K\114 L\115 M\116 N\117 O \120 P\121 Q\122 R\123 S\124 T\125 U\126 V\127 W\130 X\131 Y\132 Z\133 [\134 \\46 \&\135 ]\136 ^\137 _ \140 `\141 a\142 b\143 c\144 d\145 e\146 f\147 g\150 h\151 i\152 j\153 k\154 l\155 m\156 n\157 o \160 p\161 q\162 r\163 s\164 t\165 u\166 v\167 w\170 x\171 y\172 z\173 {\174 |\175 }\176 ~\177 \200 ?\201 ?\202 ?\203 ?\204 ?\205 ?\206 ?\207 ?\210 ?\211 ?\212 ?\213 ?\214 ?\215 ?\216 ?\217 ? \220 ?\221 ?\222 ?\223 ?\224 ?\225 ?\226 ?\227 ?\230 ?\231 ?\232 ?\233 ?\234 ?\235 ?\236 ?\237 ? \240 ?\241 ?\242 ?\243 ?\244 ?\245 ?\246 ?\247 ?\250 ?\251 ?\252 ?\253 ?\254 ?\255 ?\256 ?\257 ? \260 ?\261 ?\262 ?\263 ?\264 ?\265 ?\266 ?\267 ?\270 ?\271 ?\272 ?\273 ?\274 ?\275 ?\276 ?\277 ? \300 ?\301 ?\302 ?\303 ?\304 ?\305 ?\306 ?\307 ?\310 ?\311 ?\312 ?\313 ?\314 ?\315 ?\316 ?\317 ? \320 ?\321 ?\322 ?\323 ?\324 ?\325 ?\326 ?\327 ?\330 ?\331 ?\332 ?\333 ?\334 ?\335 ?\336 ?\337 ? \340 ?\341 ?\342 ?\343 ?\344 ?\345 ?\346 ?\347 ?\350 ?\351 ?\352 ?\353 ?\354 ?\355 ?\356 ?\357 ? \360 ?\361 ?\362 ?\363 ?\364 ?\365 ?\366 ?\367 ?\370 ?\371 ?\372 ?\373 ?\374 ?\375 ?\376 ?\377 ? ```
73,628,868
###### Updated Let's suppose that you got octal escape sequences in a stream: ``` backslash \134 is escaped as \134134 single quote ' and double quote \042 linefeed `\012` and carriage return `\015` %s & etc... ``` **note:** The escaped characters are limited to `0x01-0x1F 0x22 0x5C 0x7F` How can you revert those escape sequences back to their corresponding character with `awk`? While `awk` is able to understand them out-of-box when used in a literal string or as a parameter argument, I can't find the way to leverage this capability when the escape sequence is part of the data. For now I'm using one `gsub` per escape sequence but it doesn't feel efficient. Here's the expected output for the given sample: ``` backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` **PS:** While I have the additional constraint of unescaping each line into an awk variable before printing the result, it doesn't really matter.
2022/09/07
[ "https://Stackoverflow.com/questions/73628868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3387716/" ]
Using GNU awk for `strtonum()` and lots of meaningfully-named variables to show what each step does: ``` $ cat tst.awk function octs2chars(str, head,tail,oct,dec,char) { head = "" tail = str while ( match(tail,/\\[0-7]{3}/) ) { oct = substr(tail,RSTART+1,RLENGTH-1) dec = strtonum(0 oct) char = sprintf("%c", dec) head = head substr(tail,1,RSTART-1) char tail = substr(tail,RSTART+RLENGTH) } return head tail } { print octs2chars($0) } ``` ``` $ awk -f tst.awk file backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` If you don't have GNU awk then write a small function to convert octal to decimal, e.g. `oct2dec()` below, and then call that instead of `strtonum()`: ``` $ cat tst2.awk function oct2dec(oct, dec) { dec = substr(oct,1,1) * 8 * 8 dec += substr(oct,2,1) * 8 dec += substr(oct,3,1) return dec } function octs2chars(str, head,tail,oct,dec,char) { head = "" tail = str while ( match(tail,/\\[0-7]{3}/) ) { oct = substr(tail,RSTART+1,RLENGTH-1) dec = oct2dec(oct) # replaced "strtonum(0 oct)" char = sprintf("%c", dec) head = head substr(tail,1,RSTART-1) char tail = substr(tail,RSTART+RLENGTH) } return head tail } { print octs2chars($0) } ``` ``` $ awk -f tst2.awk file backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` The above assumes that, [as discussed in comments](https://stackoverflow.com/questions/73628868/decoding-octal-escape-sequences-in-input-with-awk?noredirect=1#comment130038302_73628868), the only backslashes in the input will be in the context of the start of octal numbers as shown in the provided sample input.
*I got my own POSIX `awk` solution, so I post it here for reference.* The main idea is to build a hash that translates an octal escape sequence to its corresponding character. You can then use it while splitting the line during the search for escape sequences: ```bash LANG=C awk ' BEGIN { for ( i = 1; i <= 255; i++ ) tr[ sprintf("\\%03o",i) ] = sprintf("%c",i) } { remainder = $0 while ( match(remainder, /\\[0-7]{3}/) ) { printf("%s%s", \ substr(remainder, 1, RSTART-1), \ tr[ substr(remainder, RSTART, RLENGTH) ] \ ) remainder = substr(remainder, RSTART + RLENGTH) } print remainder } ' input.txt ``` ``` backslash `\` single quote `'` and double quote `"` linefeed ` ` and carriage return ` %s & etc... ```
73,628,868
###### Updated Let's suppose that you got octal escape sequences in a stream: ``` backslash \134 is escaped as \134134 single quote ' and double quote \042 linefeed `\012` and carriage return `\015` %s & etc... ``` **note:** The escaped characters are limited to `0x01-0x1F 0x22 0x5C 0x7F` How can you revert those escape sequences back to their corresponding character with `awk`? While `awk` is able to understand them out-of-box when used in a literal string or as a parameter argument, I can't find the way to leverage this capability when the escape sequence is part of the data. For now I'm using one `gsub` per escape sequence but it doesn't feel efficient. Here's the expected output for the given sample: ``` backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` **PS:** While I have the additional constraint of unescaping each line into an awk variable before printing the result, it doesn't really matter.
2022/09/07
[ "https://Stackoverflow.com/questions/73628868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3387716/" ]
Using GNU awk for `strtonum()` and lots of meaningfully-named variables to show what each step does: ``` $ cat tst.awk function octs2chars(str, head,tail,oct,dec,char) { head = "" tail = str while ( match(tail,/\\[0-7]{3}/) ) { oct = substr(tail,RSTART+1,RLENGTH-1) dec = strtonum(0 oct) char = sprintf("%c", dec) head = head substr(tail,1,RSTART-1) char tail = substr(tail,RSTART+RLENGTH) } return head tail } { print octs2chars($0) } ``` ``` $ awk -f tst.awk file backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` If you don't have GNU awk then write a small function to convert octal to decimal, e.g. `oct2dec()` below, and then call that instead of `strtonum()`: ``` $ cat tst2.awk function oct2dec(oct, dec) { dec = substr(oct,1,1) * 8 * 8 dec += substr(oct,2,1) * 8 dec += substr(oct,3,1) return dec } function octs2chars(str, head,tail,oct,dec,char) { head = "" tail = str while ( match(tail,/\\[0-7]{3}/) ) { oct = substr(tail,RSTART+1,RLENGTH-1) dec = oct2dec(oct) # replaced "strtonum(0 oct)" char = sprintf("%c", dec) head = head substr(tail,1,RSTART-1) char tail = substr(tail,RSTART+RLENGTH) } return head tail } { print octs2chars($0) } ``` ``` $ awk -f tst2.awk file backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` The above assumes that, [as discussed in comments](https://stackoverflow.com/questions/73628868/decoding-octal-escape-sequences-in-input-with-awk?noredirect=1#comment130038302_73628868), the only backslashes in the input will be in the context of the start of octal numbers as shown in the provided sample input.
UPDATE :: about `gawk`'s `strtonum()` in unicode mode : ``` echo '\666' | LC_ALL='en_US.UTF-8' gawk -e ' $++NF = "<( "(sprintf("%c", strtonum((_=_<_) substr($++_, ++_))))" )>"' 0000000 909522524 539507744 690009798 2622 \ 6 6 6 < ( ƶ ** ) > \n 134 066 066 066 040 074 050 040 306 266 040 051 076 012 \ 6 6 6 sp < ( sp ? ? sp ) > nl 92 54 54 54 32 60 40 32 198 182 32 41 62 10 5c 36 36 36 20 3c 28 20 c6 b6 20 29 3e 0a 0000016 ``` By default, `gawk` in unicode mode would decode out a multi-byte character instead of byte `\266 | 0xB6`. If you wanna ensure consistency of always decoding out a single-byte out, even in `gawk` unicode mode, this should do the trick : ``` echo '\666' | LC_ALL='en_US.UTF-8' gawk -e '$++NF = sprintf("<( %c )>", strtonum((_=_<_) substr($++_, ++_)) + _*++_^_++*_^++_)' 0000000 909522524 539507744 1042882742 10 \ 6 6 6 < ( 266 ) > \n 134 066 066 066 040 074 050 040 266 040 051 076 012 \ 6 6 6 sp < ( sp ? sp ) > nl 92 54 54 54 32 60 40 32 182 32 41 62 10 5c 36 36 36 20 3c 28 20 b6 20 29 3e 0a 0000015 ``` ***long story short*** : add `4^5 * 54` to output of `strtonum()`, which happens to be `0xD800`, the starting point of `UTF-16 surrogates` =================== =================== =================== one quick note about `@Gene`'s proposed `perl`-based solution : ``` echo 'abc \555 456' | perl -p -e 's/\\([0-7]{3})/chr(oct($1))/ge' Wide character in print at -e line 1, <> line 1. abc ŭ 456 ``` octal codes wrap around, meaning `\4xx = \0xx ; \6xx = \2xx` etc : ``` printf '\n %s\n' $'\555' m ``` so `perl` is incorrectly decoding these as multi-byte characters, when in fact `\555`, as confirmed by `printf`, is merely lowercase `"m" (0x6D)` ps : my `perl` is version `5.34`
73,628,868
###### Updated Let's suppose that you got octal escape sequences in a stream: ``` backslash \134 is escaped as \134134 single quote ' and double quote \042 linefeed `\012` and carriage return `\015` %s & etc... ``` **note:** The escaped characters are limited to `0x01-0x1F 0x22 0x5C 0x7F` How can you revert those escape sequences back to their corresponding character with `awk`? While `awk` is able to understand them out-of-box when used in a literal string or as a parameter argument, I can't find the way to leverage this capability when the escape sequence is part of the data. For now I'm using one `gsub` per escape sequence but it doesn't feel efficient. Here's the expected output for the given sample: ``` backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` **PS:** While I have the additional constraint of unescaping each line into an awk variable before printing the result, it doesn't really matter.
2022/09/07
[ "https://Stackoverflow.com/questions/73628868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3387716/" ]
Using GNU awk for `strtonum()` and lots of meaningfully-named variables to show what each step does: ``` $ cat tst.awk function octs2chars(str, head,tail,oct,dec,char) { head = "" tail = str while ( match(tail,/\\[0-7]{3}/) ) { oct = substr(tail,RSTART+1,RLENGTH-1) dec = strtonum(0 oct) char = sprintf("%c", dec) head = head substr(tail,1,RSTART-1) char tail = substr(tail,RSTART+RLENGTH) } return head tail } { print octs2chars($0) } ``` ``` $ awk -f tst.awk file backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` If you don't have GNU awk then write a small function to convert octal to decimal, e.g. `oct2dec()` below, and then call that instead of `strtonum()`: ``` $ cat tst2.awk function oct2dec(oct, dec) { dec = substr(oct,1,1) * 8 * 8 dec += substr(oct,2,1) * 8 dec += substr(oct,3,1) return dec } function octs2chars(str, head,tail,oct,dec,char) { head = "" tail = str while ( match(tail,/\\[0-7]{3}/) ) { oct = substr(tail,RSTART+1,RLENGTH-1) dec = oct2dec(oct) # replaced "strtonum(0 oct)" char = sprintf("%c", dec) head = head substr(tail,1,RSTART-1) char tail = substr(tail,RSTART+RLENGTH) } return head tail } { print octs2chars($0) } ``` ``` $ awk -f tst2.awk file backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` The above assumes that, [as discussed in comments](https://stackoverflow.com/questions/73628868/decoding-octal-escape-sequences-in-input-with-awk?noredirect=1#comment130038302_73628868), the only backslashes in the input will be in the context of the start of octal numbers as shown in the provided sample input.
this separate post is made specifically to showcase how to extend the octal lookup reference tables in `gawk` `unicode`-mode to ***`all 256 bytes`*** without external dependencies or warning messages: * `ASCII` bytes reside in table `o2bL` * 8-bit bytes reside in table `o2bH` . ``` # gawk profile, created Fri Sep 16 09:53:26 2022 'BEGIN { 1 makeOctalRefTables(PROCINFO["sorted_in"] = "@val_str_asc" \ (ORS = "")) 128 for (_ in o2bL) { 128 print o2bL[_] } 128 for (_ in o2bH) { 128 print o2bH[_] } } function makeOctalRefTables(_,__,___,____) { 1 _=__=___=____="" for (_ in o2bL) { break } 1 if (!(_ in o2bL)) { 1 ____=_+=((_+=_^=_<_)-+-++_)^_-- 128 do { o2bL[sprintf("\\%o",_)] = \ sprintf("""%c",_) } while (_--) 1 o2bL["\\" ((_+=(_+=_^=_<_)+_)*_--+_+_)] = "\\&" 1 ___=--_*_^_--*--_*++_^_*(_^=++_)^(! —_) 128 do { o2bH[sprintf("\\%o", +_)] = \ sprintf("%c",___+_) } while (____<--_) } 1 return length(o2bL) ":" length(o2bH) }' ``` | ``` \0 \1 \2 \3 \4 \5 \6 \7 \10\11 \12 \13 \14 \16 \17 \20 \21 \22 \23 \24 \25 \26 \27 \30 \31 \32 \33 34 \35 \36 \37 \40 \41 !\42 "\43 #\44 $\45 %\47 '\50 (\51 )\52 *\53 +\54 ,\55 -\56 .\57 / \60 0\61 1\62 2\63 3\64 4\65 5\66 6\67 7\70 8\71 9\72 :\73 ;\74 <\75 =\76 >\77 ? \100 @\101 A\102 B\103 C\104 D\105 E\106 F\107 G\110 H\111 I\112 J\113 K\114 L\115 M\116 N\117 O \120 P\121 Q\122 R\123 S\124 T\125 U\126 V\127 W\130 X\131 Y\132 Z\133 [\134 \\46 \&\135 ]\136 ^\137 _ \140 `\141 a\142 b\143 c\144 d\145 e\146 f\147 g\150 h\151 i\152 j\153 k\154 l\155 m\156 n\157 o \160 p\161 q\162 r\163 s\164 t\165 u\166 v\167 w\170 x\171 y\172 z\173 {\174 |\175 }\176 ~\177 \200 ?\201 ?\202 ?\203 ?\204 ?\205 ?\206 ?\207 ?\210 ?\211 ?\212 ?\213 ?\214 ?\215 ?\216 ?\217 ? \220 ?\221 ?\222 ?\223 ?\224 ?\225 ?\226 ?\227 ?\230 ?\231 ?\232 ?\233 ?\234 ?\235 ?\236 ?\237 ? \240 ?\241 ?\242 ?\243 ?\244 ?\245 ?\246 ?\247 ?\250 ?\251 ?\252 ?\253 ?\254 ?\255 ?\256 ?\257 ? \260 ?\261 ?\262 ?\263 ?\264 ?\265 ?\266 ?\267 ?\270 ?\271 ?\272 ?\273 ?\274 ?\275 ?\276 ?\277 ? \300 ?\301 ?\302 ?\303 ?\304 ?\305 ?\306 ?\307 ?\310 ?\311 ?\312 ?\313 ?\314 ?\315 ?\316 ?\317 ? \320 ?\321 ?\322 ?\323 ?\324 ?\325 ?\326 ?\327 ?\330 ?\331 ?\332 ?\333 ?\334 ?\335 ?\336 ?\337 ? \340 ?\341 ?\342 ?\343 ?\344 ?\345 ?\346 ?\347 ?\350 ?\351 ?\352 ?\353 ?\354 ?\355 ?\356 ?\357 ? \360 ?\361 ?\362 ?\363 ?\364 ?\365 ?\366 ?\367 ?\370 ?\371 ?\372 ?\373 ?\374 ?\375 ?\376 ?\377 ? ```
73,628,868
###### Updated Let's suppose that you got octal escape sequences in a stream: ``` backslash \134 is escaped as \134134 single quote ' and double quote \042 linefeed `\012` and carriage return `\015` %s & etc... ``` **note:** The escaped characters are limited to `0x01-0x1F 0x22 0x5C 0x7F` How can you revert those escape sequences back to their corresponding character with `awk`? While `awk` is able to understand them out-of-box when used in a literal string or as a parameter argument, I can't find the way to leverage this capability when the escape sequence is part of the data. For now I'm using one `gsub` per escape sequence but it doesn't feel efficient. Here's the expected output for the given sample: ``` backslash \ is escaped as \134 single quote ' and double quote " linefeed ` ` and carriage return ` %s & etc... ``` **PS:** While I have the additional constraint of unescaping each line into an awk variable before printing the result, it doesn't really matter.
2022/09/07
[ "https://Stackoverflow.com/questions/73628868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3387716/" ]
*I got my own POSIX `awk` solution, so I post it here for reference.* The main idea is to build a hash that translates an octal escape sequence to its corresponding character. You can then use it while splitting the line during the search for escape sequences: ```bash LANG=C awk ' BEGIN { for ( i = 1; i <= 255; i++ ) tr[ sprintf("\\%03o",i) ] = sprintf("%c",i) } { remainder = $0 while ( match(remainder, /\\[0-7]{3}/) ) { printf("%s%s", \ substr(remainder, 1, RSTART-1), \ tr[ substr(remainder, RSTART, RLENGTH) ] \ ) remainder = substr(remainder, RSTART + RLENGTH) } print remainder } ' input.txt ``` ``` backslash `\` single quote `'` and double quote `"` linefeed ` ` and carriage return ` %s & etc... ```
this separate post is made specifically to showcase how to extend the octal lookup reference tables in `gawk` `unicode`-mode to ***`all 256 bytes`*** without external dependencies or warning messages: * `ASCII` bytes reside in table `o2bL` * 8-bit bytes reside in table `o2bH` . ``` # gawk profile, created Fri Sep 16 09:53:26 2022 'BEGIN { 1 makeOctalRefTables(PROCINFO["sorted_in"] = "@val_str_asc" \ (ORS = "")) 128 for (_ in o2bL) { 128 print o2bL[_] } 128 for (_ in o2bH) { 128 print o2bH[_] } } function makeOctalRefTables(_,__,___,____) { 1 _=__=___=____="" for (_ in o2bL) { break } 1 if (!(_ in o2bL)) { 1 ____=_+=((_+=_^=_<_)-+-++_)^_-- 128 do { o2bL[sprintf("\\%o",_)] = \ sprintf("""%c",_) } while (_--) 1 o2bL["\\" ((_+=(_+=_^=_<_)+_)*_--+_+_)] = "\\&" 1 ___=--_*_^_--*--_*++_^_*(_^=++_)^(! —_) 128 do { o2bH[sprintf("\\%o", +_)] = \ sprintf("%c",___+_) } while (____<--_) } 1 return length(o2bL) ":" length(o2bH) }' ``` | ``` \0 \1 \2 \3 \4 \5 \6 \7 \10\11 \12 \13 \14 \16 \17 \20 \21 \22 \23 \24 \25 \26 \27 \30 \31 \32 \33 34 \35 \36 \37 \40 \41 !\42 "\43 #\44 $\45 %\47 '\50 (\51 )\52 *\53 +\54 ,\55 -\56 .\57 / \60 0\61 1\62 2\63 3\64 4\65 5\66 6\67 7\70 8\71 9\72 :\73 ;\74 <\75 =\76 >\77 ? \100 @\101 A\102 B\103 C\104 D\105 E\106 F\107 G\110 H\111 I\112 J\113 K\114 L\115 M\116 N\117 O \120 P\121 Q\122 R\123 S\124 T\125 U\126 V\127 W\130 X\131 Y\132 Z\133 [\134 \\46 \&\135 ]\136 ^\137 _ \140 `\141 a\142 b\143 c\144 d\145 e\146 f\147 g\150 h\151 i\152 j\153 k\154 l\155 m\156 n\157 o \160 p\161 q\162 r\163 s\164 t\165 u\166 v\167 w\170 x\171 y\172 z\173 {\174 |\175 }\176 ~\177 \200 ?\201 ?\202 ?\203 ?\204 ?\205 ?\206 ?\207 ?\210 ?\211 ?\212 ?\213 ?\214 ?\215 ?\216 ?\217 ? \220 ?\221 ?\222 ?\223 ?\224 ?\225 ?\226 ?\227 ?\230 ?\231 ?\232 ?\233 ?\234 ?\235 ?\236 ?\237 ? \240 ?\241 ?\242 ?\243 ?\244 ?\245 ?\246 ?\247 ?\250 ?\251 ?\252 ?\253 ?\254 ?\255 ?\256 ?\257 ? \260 ?\261 ?\262 ?\263 ?\264 ?\265 ?\266 ?\267 ?\270 ?\271 ?\272 ?\273 ?\274 ?\275 ?\276 ?\277 ? \300 ?\301 ?\302 ?\303 ?\304 ?\305 ?\306 ?\307 ?\310 ?\311 ?\312 ?\313 ?\314 ?\315 ?\316 ?\317 ? \320 ?\321 ?\322 ?\323 ?\324 ?\325 ?\326 ?\327 ?\330 ?\331 ?\332 ?\333 ?\334 ?\335 ?\336 ?\337 ? \340 ?\341 ?\342 ?\343 ?\344 ?\345 ?\346 ?\347 ?\350 ?\351 ?\352 ?\353 ?\354 ?\355 ?\356 ?\357 ? \360 ?\361 ?\362 ?\363 ?\364 ?\365 ?\366 ?\367 ?\370 ?\371 ?\372 ?\373 ?\374 ?\375 ?\376 ?\377 ? ```