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
12,242,879
In my project I have to select multiple values and pass it to a query. i.e page1 contains checkboxes. I am storing the selected checkbox id's into an array. I am shuffling that array and getting the values randomly. Now I need to pass these random values to a query. Using IN operator in database I can pass the values statically but how can I pass the values dynamcially to the query. For ex:(Passing values statically) ``` SELECT * FROM Persons WHERE person_id IN ('21','22') ``` In the above query the id's 21 and 22 are know previously and so we are passing statically but I want to send the values to query dynamically. ``` Page1: public static ArrayList<String> chksublist = new ArrayList<String>(); Page2: Collections.shuffle(chksublist ); SELECT * FROM Persons WHERE person_id IN ('21','22') In the above line I want to send the random values which are in chksublist array. ```
2012/09/03
[ "https://Stackoverflow.com/questions/12242879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1455252/" ]
You can generate your query like this ``` int values[]; //it contains your generated values like 21,22.... String query="SELECT * FROM Persons WHERE person_id IN ("; for(int i=0;i<values.length;i++){ query=query+"'"+values[i]+"'"; if(i<values.length-1){ query=query+","; //No , after last values } } query+=")"; ``` finally pass this query.
Try it ``` cursor = database.query(tablename, new String[] {"TopName"}, "id IN(?,?)", new String[]{"2","3"}, null, null, null); ``` using raw query ``` String query = "SELECT * FROM Persons WHERE person_id IN ("+parameter1+","+parameter2+")"; db.rawQuery(query); ```
12,242,879
In my project I have to select multiple values and pass it to a query. i.e page1 contains checkboxes. I am storing the selected checkbox id's into an array. I am shuffling that array and getting the values randomly. Now I need to pass these random values to a query. Using IN operator in database I can pass the values statically but how can I pass the values dynamcially to the query. For ex:(Passing values statically) ``` SELECT * FROM Persons WHERE person_id IN ('21','22') ``` In the above query the id's 21 and 22 are know previously and so we are passing statically but I want to send the values to query dynamically. ``` Page1: public static ArrayList<String> chksublist = new ArrayList<String>(); Page2: Collections.shuffle(chksublist ); SELECT * FROM Persons WHERE person_id IN ('21','22') In the above line I want to send the random values which are in chksublist array. ```
2012/09/03
[ "https://Stackoverflow.com/questions/12242879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1455252/" ]
`String query = "SELECT * FROM Persons WHERE person_id IN (" + TextUtils.join(",", chksublist) + ")";` But shuffling the `chksublist` before sending it to your SQL query has no impact on the result set you get from SQL. It will not randomly permute your results. Remove `Collections.shuffle(chksublist);` and use `String query = "SELECT * FROM Persons WHERE person_id IN (" + TextUtils.join(",", chksublist) + ") ORDER BY RANDOM()";`
You can generate your query like this ``` int values[]; //it contains your generated values like 21,22.... String query="SELECT * FROM Persons WHERE person_id IN ("; for(int i=0;i<values.length;i++){ query=query+"'"+values[i]+"'"; if(i<values.length-1){ query=query+","; //No , after last values } } query+=")"; ``` finally pass this query.
12,242,879
In my project I have to select multiple values and pass it to a query. i.e page1 contains checkboxes. I am storing the selected checkbox id's into an array. I am shuffling that array and getting the values randomly. Now I need to pass these random values to a query. Using IN operator in database I can pass the values statically but how can I pass the values dynamcially to the query. For ex:(Passing values statically) ``` SELECT * FROM Persons WHERE person_id IN ('21','22') ``` In the above query the id's 21 and 22 are know previously and so we are passing statically but I want to send the values to query dynamically. ``` Page1: public static ArrayList<String> chksublist = new ArrayList<String>(); Page2: Collections.shuffle(chksublist ); SELECT * FROM Persons WHERE person_id IN ('21','22') In the above line I want to send the random values which are in chksublist array. ```
2012/09/03
[ "https://Stackoverflow.com/questions/12242879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1455252/" ]
`String query = "SELECT * FROM Persons WHERE person_id IN (" + TextUtils.join(",", chksublist) + ")";` But shuffling the `chksublist` before sending it to your SQL query has no impact on the result set you get from SQL. It will not randomly permute your results. Remove `Collections.shuffle(chksublist);` and use `String query = "SELECT * FROM Persons WHERE person_id IN (" + TextUtils.join(",", chksublist) + ") ORDER BY RANDOM()";`
Try it ``` cursor = database.query(tablename, new String[] {"TopName"}, "id IN(?,?)", new String[]{"2","3"}, null, null, null); ``` using raw query ``` String query = "SELECT * FROM Persons WHERE person_id IN ("+parameter1+","+parameter2+")"; db.rawQuery(query); ```
107,973
[iOS Human Interface Guidelines](https://developer.apple.com/ios/human-interface-guidelines/graphics/launch-screen/) say: > > Design a launch screen that’s nearly identical to the first screen > of your app. If you include elements that look different when the app > finishes launching, people can experience an unpleasant flash between > the launch screen and the first screen of the app. > > > The quote from [iOS Human Interface Guidelines](https://developer.apple.com/ios/human-interface-guidelines/interaction/first-launch-experience/) about **splash screens**: > > Get to the action quickly. Avoid showing a splash screen, menus, and > instructions that make it take longer to reach content and start using > your app. Instead, let people dive right in. > > > But Twitter still has splash screen and designers are ignoring guidelines writing articles [how to use branding in splash sreen design](https://medium.com/ux-power-tools/dead-simple-techniques-for-using-branding-in-ui-d44cb44e40ee?ref=prototyprio). What is their motivation and consequences on usability for ignoring these guidelines?
2017/05/13
[ "https://ux.stackexchange.com/questions/107973", "https://ux.stackexchange.com", "https://ux.stackexchange.com/users/68624/" ]
Maybe they are using other guidelines. You have the iOS Human Interface Guidelines, but also Material Design Guidelines. They are not OS-bound. Google applications on iOS also use Material Design. [Material Design guidelines](https://material.io/guidelines/patterns/launch-screens.html#launch-screens-types-of-launch-screens) for example talk about two kinds of splash screens. > > A **placeholder UI** displays core structural elements such as the > status and app bars until the app has loaded. > > > And > > **Branded launch screens** display your logo or other elements that > improve brand recognition. > > > We can't know for sure why they did what they did but the above mentioned **branded launch screen** makes sense for me. The rest of the Twitter application is pretty clean of branding.
I know that in some cases splash screens are a must due to technical reasons. Depending on how the code of the app is written, it may take some time for the app to load when launched so splash screens are used for that reason.
19,564,281
I am trying to submit this form without refreshing the page , but when i submit it takes me to action page. what is wrong with my code? This is my form: ``` <form class="ajax" action="/../addchannel/createUser.php" method="post" > <input type="text" name="userName" placeholder="userName"><br> <input type="text" name="email" placeholder="email"><br> <input type="submit" value="submit" > </form>'; ``` And this is my script: ``` $('form.ajax').on('submit', function () { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); }); ```
2013/10/24
[ "https://Stackoverflow.com/questions/19564281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2866602/" ]
You forgot `return false` at the end or prevent default. ``` $('form.ajax').on('submit', function (event) { event.preventDefault(); var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; .... //or return false; }); ```
Use [e.preventDefault()](http://api.jquery.com/event.preventDefault/) or `return false;` to prevent form submitting ``` $('form.ajax').on('submit', function (e) {//Pass the event argument here var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); e.preventDefault(); //OR return false; }); ```
19,564,281
I am trying to submit this form without refreshing the page , but when i submit it takes me to action page. what is wrong with my code? This is my form: ``` <form class="ajax" action="/../addchannel/createUser.php" method="post" > <input type="text" name="userName" placeholder="userName"><br> <input type="text" name="email" placeholder="email"><br> <input type="submit" value="submit" > </form>'; ``` And this is my script: ``` $('form.ajax').on('submit', function () { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); }); ```
2013/10/24
[ "https://Stackoverflow.com/questions/19564281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2866602/" ]
You forgot `return false` at the end or prevent default. ``` $('form.ajax').on('submit', function (event) { event.preventDefault(); var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; .... //or return false; }); ```
Use [event.preventDefault()](http://api.jquery.com/event.preventDefault/) ``` $('form.ajax').on('submit', function (e) { e.preventDefault(); //code here }); ```
19,564,281
I am trying to submit this form without refreshing the page , but when i submit it takes me to action page. what is wrong with my code? This is my form: ``` <form class="ajax" action="/../addchannel/createUser.php" method="post" > <input type="text" name="userName" placeholder="userName"><br> <input type="text" name="email" placeholder="email"><br> <input type="submit" value="submit" > </form>'; ``` And this is my script: ``` $('form.ajax').on('submit', function () { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); }); ```
2013/10/24
[ "https://Stackoverflow.com/questions/19564281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2866602/" ]
You forgot `return false` at the end or prevent default. ``` $('form.ajax').on('submit', function (event) { event.preventDefault(); var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; .... //or return false; }); ```
try this.. ``` <form method='post' action="javascript:mail();" > <input type="text" class="input-large" id="user_name" name="name"> <input type="text" class="input-large" id="email" name="name"> <button type="submit" class="btn btn-primary">Submit</a> </form> function mail() { var name = $("#user_name").val(); var email = $("#email").val(); $.ajax({ type: "POST", url: "contact.php", data: "name=" + name+"&customer_mail="+email, success: function(html) { //do ur function } }); } ```
19,564,281
I am trying to submit this form without refreshing the page , but when i submit it takes me to action page. what is wrong with my code? This is my form: ``` <form class="ajax" action="/../addchannel/createUser.php" method="post" > <input type="text" name="userName" placeholder="userName"><br> <input type="text" name="email" placeholder="email"><br> <input type="submit" value="submit" > </form>'; ``` And this is my script: ``` $('form.ajax').on('submit', function () { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); }); ```
2013/10/24
[ "https://Stackoverflow.com/questions/19564281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2866602/" ]
You forgot `return false` at the end or prevent default. ``` $('form.ajax').on('submit', function (event) { event.preventDefault(); var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; .... //or return false; }); ```
Using jQuery ajax is not preventing browser to follow Form Action page. To achieve this, you should prevent browser to do it by simple function: [e.preventDefault()](http://api.jquery.com/event.preventDefault/) Here is you code: ``` //Pass the event argument (e) $('form.ajax').on('submit', function (e) { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); //Prevent Browser to follow form action link: e.preventDefault(); //you can use also // return false; }); ```
19,564,281
I am trying to submit this form without refreshing the page , but when i submit it takes me to action page. what is wrong with my code? This is my form: ``` <form class="ajax" action="/../addchannel/createUser.php" method="post" > <input type="text" name="userName" placeholder="userName"><br> <input type="text" name="email" placeholder="email"><br> <input type="submit" value="submit" > </form>'; ``` And this is my script: ``` $('form.ajax').on('submit', function () { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); }); ```
2013/10/24
[ "https://Stackoverflow.com/questions/19564281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2866602/" ]
Pass event as argument and use `event.preventDefault()`. **Example** ``` $('form.ajax').on('submit', function (e) { e.preventDefault(); ```
Use [e.preventDefault()](http://api.jquery.com/event.preventDefault/) or `return false;` to prevent form submitting ``` $('form.ajax').on('submit', function (e) {//Pass the event argument here var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); e.preventDefault(); //OR return false; }); ```
19,564,281
I am trying to submit this form without refreshing the page , but when i submit it takes me to action page. what is wrong with my code? This is my form: ``` <form class="ajax" action="/../addchannel/createUser.php" method="post" > <input type="text" name="userName" placeholder="userName"><br> <input type="text" name="email" placeholder="email"><br> <input type="submit" value="submit" > </form>'; ``` And this is my script: ``` $('form.ajax').on('submit', function () { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); }); ```
2013/10/24
[ "https://Stackoverflow.com/questions/19564281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2866602/" ]
Pass event as argument and use `event.preventDefault()`. **Example** ``` $('form.ajax').on('submit', function (e) { e.preventDefault(); ```
Use [event.preventDefault()](http://api.jquery.com/event.preventDefault/) ``` $('form.ajax').on('submit', function (e) { e.preventDefault(); //code here }); ```
19,564,281
I am trying to submit this form without refreshing the page , but when i submit it takes me to action page. what is wrong with my code? This is my form: ``` <form class="ajax" action="/../addchannel/createUser.php" method="post" > <input type="text" name="userName" placeholder="userName"><br> <input type="text" name="email" placeholder="email"><br> <input type="submit" value="submit" > </form>'; ``` And this is my script: ``` $('form.ajax').on('submit', function () { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); }); ```
2013/10/24
[ "https://Stackoverflow.com/questions/19564281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2866602/" ]
Pass event as argument and use `event.preventDefault()`. **Example** ``` $('form.ajax').on('submit', function (e) { e.preventDefault(); ```
try this.. ``` <form method='post' action="javascript:mail();" > <input type="text" class="input-large" id="user_name" name="name"> <input type="text" class="input-large" id="email" name="name"> <button type="submit" class="btn btn-primary">Submit</a> </form> function mail() { var name = $("#user_name").val(); var email = $("#email").val(); $.ajax({ type: "POST", url: "contact.php", data: "name=" + name+"&customer_mail="+email, success: function(html) { //do ur function } }); } ```
19,564,281
I am trying to submit this form without refreshing the page , but when i submit it takes me to action page. what is wrong with my code? This is my form: ``` <form class="ajax" action="/../addchannel/createUser.php" method="post" > <input type="text" name="userName" placeholder="userName"><br> <input type="text" name="email" placeholder="email"><br> <input type="submit" value="submit" > </form>'; ``` And this is my script: ``` $('form.ajax').on('submit', function () { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); }); ```
2013/10/24
[ "https://Stackoverflow.com/questions/19564281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2866602/" ]
Pass event as argument and use `event.preventDefault()`. **Example** ``` $('form.ajax').on('submit', function (e) { e.preventDefault(); ```
Using jQuery ajax is not preventing browser to follow Form Action page. To achieve this, you should prevent browser to do it by simple function: [e.preventDefault()](http://api.jquery.com/event.preventDefault/) Here is you code: ``` //Pass the event argument (e) $('form.ajax').on('submit', function (e) { var that = $(this), url = that.attr('action'), type = that.attr('method'), data = {}; that.find(['name']).each(function (index, value)) { var that = $(this), name = that.attr('name'), value = that.val(); data[name] = value; }); $.ajax({ url: url, type: type, data: data, success: function (response) { consol.log(response) } }); //Prevent Browser to follow form action link: e.preventDefault(); //you can use also // return false; }); ```
755,680
I am running the code below and the result is totally different when it runs in Release mode. While in Debug mode, it never collects the object of class A and in Reaelse mode it immediately collects the object of class A. Can someone explain why. ``` using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { A obj = new A(); B bobj = obj.objB; GC.Collect(); GC.WaitForPendingFinalizers(); while (bobj.isLive) { Console.WriteLine("Is Alive!!"); } Console.WriteLine("Is Dead!!"); Console.ReadLine(); } } class A:IDisposable { public B objB = new B(); public A() { } ~A() { objB.Dispose(); } #region IDisposable Members public void Dispose() { GC.SuppressFinalize(this); } #endregion } class B:IDisposable { public bool isLive = true; #region IDisposable Members public void Dispose() { this.isLive = false; GC.SuppressFinalize(this); } #endregion } } ```
2009/04/16
[ "https://Stackoverflow.com/questions/755680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17296/" ]
In Debug mode, the compiler does not optimize the local variables. Therefore, the reference to A still exists. In Release mode, the compiler optimized the usage so that the reference is thrown away and the object can be collected.
The garbage collector handles variable usage differently in debug mode and release mode. In release mode the usage of a variable is only where it's actually used. After the last use of the varaible, the object is up for garbage collection. In debug mode the usage of a varaible is expanded to it's scope. The reason for this is so that the watch window in the debugger can show the value of a variables throughout it's scope.
755,680
I am running the code below and the result is totally different when it runs in Release mode. While in Debug mode, it never collects the object of class A and in Reaelse mode it immediately collects the object of class A. Can someone explain why. ``` using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { A obj = new A(); B bobj = obj.objB; GC.Collect(); GC.WaitForPendingFinalizers(); while (bobj.isLive) { Console.WriteLine("Is Alive!!"); } Console.WriteLine("Is Dead!!"); Console.ReadLine(); } } class A:IDisposable { public B objB = new B(); public A() { } ~A() { objB.Dispose(); } #region IDisposable Members public void Dispose() { GC.SuppressFinalize(this); } #endregion } class B:IDisposable { public bool isLive = true; #region IDisposable Members public void Dispose() { this.isLive = false; GC.SuppressFinalize(this); } #endregion } } ```
2009/04/16
[ "https://Stackoverflow.com/questions/755680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17296/" ]
In Debug mode, the compiler does not optimize the local variables. Therefore, the reference to A still exists. In Release mode, the compiler optimized the usage so that the reference is thrown away and the object can be collected.
I just found this behavior in my tests. Inserting ``` obj = null; ``` right before GC.Collect() should help. I think that is kind of "simulated" optimization.
39,094,332
Most probably I oversee something in this trivial use case. My code iterates over annotated fields in a class and the for every field I'd like to run some code dependent on the type. The simplest is just to set a value: ``` field.setAccessible(true); final Class<?> type = field.getType(); if (type.equals(Boolean.class)) { field.set(this, Boolean.parseBoolean(property)); } else if (type.equals(Integer.class)) { field.set(this, Integer.parseInt(property)); } else if (type.equals(String.class)) { field.set(this, property); } else { LOGGER.warn("Cannot parse property -{}{}. Unknown type defined.", option.getOpt(), field.getName()); } ``` However this check: ``` if (type.equals(Boolean.class)) ``` dosn't work as expected e.g. for a field defined as `private boolean isVerbose;`. After inspection of `type` I got the property `name` as just only `"boolean"` where the `Boolean.class` property `name` was filled with `"java.lang.Boolean"`. These object were different. What would be the right implementation of this scenario?
2016/08/23
[ "https://Stackoverflow.com/questions/39094332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2650481/" ]
Take a look at this post: [Check type of primitive field](https://stackoverflow.com/questions/1891595/check-type-of-primitive-field) basically you need to check primitive types separately (`Boolean.TYPE`, `Long.TYPE` etc) ``` if (field.getType().equals(Boolean.TYPE) { // do something if field is boolean } ```
In Java, `boolean` and `Boolean` are two different types: `boolean` is a primitive data type while `Boolean` is a class in `java.lang.Boolean`. In this example, in your class you are using `private boolean isVerbose` which is not of type `java.lang.Boolean`. Hence you have to change it to `private Boolean isVerbose`. Hope this helps !!!!!!
39,094,332
Most probably I oversee something in this trivial use case. My code iterates over annotated fields in a class and the for every field I'd like to run some code dependent on the type. The simplest is just to set a value: ``` field.setAccessible(true); final Class<?> type = field.getType(); if (type.equals(Boolean.class)) { field.set(this, Boolean.parseBoolean(property)); } else if (type.equals(Integer.class)) { field.set(this, Integer.parseInt(property)); } else if (type.equals(String.class)) { field.set(this, property); } else { LOGGER.warn("Cannot parse property -{}{}. Unknown type defined.", option.getOpt(), field.getName()); } ``` However this check: ``` if (type.equals(Boolean.class)) ``` dosn't work as expected e.g. for a field defined as `private boolean isVerbose;`. After inspection of `type` I got the property `name` as just only `"boolean"` where the `Boolean.class` property `name` was filled with `"java.lang.Boolean"`. These object were different. What would be the right implementation of this scenario?
2016/08/23
[ "https://Stackoverflow.com/questions/39094332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2650481/" ]
Take a look at this post: [Check type of primitive field](https://stackoverflow.com/questions/1891595/check-type-of-primitive-field) basically you need to check primitive types separately (`Boolean.TYPE`, `Long.TYPE` etc) ``` if (field.getType().equals(Boolean.TYPE) { // do something if field is boolean } ```
I believe you are having troubles with the java primitives and the boxing. java.lang.Boolean is a class, where as "boolean" just denotes the primitive type. It is a difference wether you declare: ``` private boolean myBool; // this a java primitive private Boolean myOtherBool; // this is an object ``` Java automatically converts between those types as needed, but as you are inspecting the type yourself you have to pay attention to this. The same goes for: - Integer - Long - Short - Byte I hope I did not forget anything.
11,252,639
The existing dialog plugin doesn't have an option to close dialog on clicking modal overlay, how to add an option to provide the functionality?
2012/06/28
[ "https://Stackoverflow.com/questions/11252639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/342553/" ]
``` (function($){ var _init = $.ui.dialog.prototype._init; $.ui.dialog.prototype._init = function(){ var self = this; _init.apply(this,arguments); $('.ui-widget-overlay').live('click', function(){ if (self.options['overlay_close']){ self.destroy(); } }); } })($); ```
It would be even better if the self-provided answer worked. I get no response when clicking outside the dialog. Here is my [jsFiddle](http://jsfiddle.net/styson/menjK/) for testing. Maybe I am doing something wrong, but it doesn't seem to do its desired function. @JamesLin provided the key insight. I needed to add the new option in my initialization: ``` $("#myDialog").dialog({ overlay_close:true, modal: true }); ``` The jsFiddle is also updated.
3,500,967
Can some body explain why the TD element is taking width when its not allowed in strict mode.This is the code [Was not able to put code because of HTML rendering problem.] ``` <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/xml+xhtml; charset=utf-8"/> </head> <body> <table> <tr> <td width="200">First</td> <td>Second</td> </tr> </table> </body> </html> ```
2010/08/17
[ "https://Stackoverflow.com/questions/3500967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/341144/" ]
Even though it's deprecated per the spec the browser will still apply it because you specified it. It has to be lenient toward older docs which may otherwise have broken layouts if it didn't apply the attribute(s).
Since you specified it the browser will apply it, but your document won't validate.
3,500,967
Can some body explain why the TD element is taking width when its not allowed in strict mode.This is the code [Was not able to put code because of HTML rendering problem.] ``` <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/xml+xhtml; charset=utf-8"/> </head> <body> <table> <tr> <td width="200">First</td> <td>Second</td> </tr> </table> </body> </html> ```
2010/08/17
[ "https://Stackoverflow.com/questions/3500967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/341144/" ]
Even though it's deprecated per the spec the browser will still apply it because you specified it. It has to be lenient toward older docs which may otherwise have broken layouts if it didn't apply the attribute(s).
Your doctype (HTML 4.01) doesn't match your content type. The content type should read `application/xhtml+xml` instead of `text/xml+xhtml`, *and* your web server should also serve your page as such in order for standards-compliant browsers to treat it strictly (that is, fail to render your document if it's invalid). Also, as Alohci says, you need to include an XML namespace for the XHTML spec. ``` <html xmlns="http://www.w3.org/1999/xhtml"> ``` Otherwise, browsers will just render like you tell them to, ignoring standards, although if you try to validate this it'll still fail.
3,500,967
Can some body explain why the TD element is taking width when its not allowed in strict mode.This is the code [Was not able to put code because of HTML rendering problem.] ``` <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/xml+xhtml; charset=utf-8"/> </head> <body> <table> <tr> <td width="200">First</td> <td>Second</td> </tr> </table> </body> </html> ```
2010/08/17
[ "https://Stackoverflow.com/questions/3500967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/341144/" ]
Even though it's deprecated per the spec the browser will still apply it because you specified it. It has to be lenient toward older docs which may otherwise have broken layouts if it didn't apply the attribute(s).
I did everything suggested but it still it is taking width attribute. I think it is because of browsers have to support it now but future browsers will throw an error on code like this
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
i had this issue and it was a directory name capitalization problem. i was importing my component like this : ``` ../proxies/test.component ../Proxies/test.component ```
In my case, when renaming the folder I made a capitalization error, then corrected it. Somehow, visual studio created a second directory with the bad capitalization. That second directory was invisible in VS, but when I tracked it down manually I was able to delete it. After restarting VS code to force it to recognize the correct folder, I was able to get it working again.
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
I had a similar issue and solved it by closing the folder, then on the Recent workspaces list click More at the bottom, and from the list click the 'x' (remove) button to remove the workspace. Then, after loading the project's folder, it build normally. So probably there is some cache and that is probably one way to clear it.
I have the same issue, and just discovered that for some reason, in some ts file it is called using capitalize letter, then I renamed it for lowercase and it works. You can try also removing this model ts file and creating again with angular-CLI.
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
i had this issue and it was a directory name capitalization problem. i was importing my component like this : ``` ../proxies/test.component ../Proxies/test.component ```
I have the same issue, and just discovered that for some reason, in some ts file it is called using capitalize letter, then I renamed it for lowercase and it works. You can try also removing this model ts file and creating again with angular-CLI.
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
i had this issue and it was a directory name capitalization problem. i was importing my component like this : ``` ../proxies/test.component ../Proxies/test.component ```
I solved it by restarting typescript server: Make sure that you have a TypeScript file open, press Ctrl+Shift+P (or Cmd+Shift+P on macOS) to open the Command Palette and type restart, then select the command "TypeScript: Restart TS server". [Source](https://tinytip.co/tips/vscode-restart-ts/#:%7E:text=You%20can%20restart%20the%20server,TypeScript%3A%20Restart%20TS%20server%22.)
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
I had a similar issue and solved it by closing the folder, then on the Recent workspaces list click More at the bottom, and from the list click the 'x' (remove) button to remove the workspace. Then, after loading the project's folder, it build normally. So probably there is some cache and that is probably one way to clear it.
In my case, when renaming the folder I made a capitalization error, then corrected it. Somehow, visual studio created a second directory with the bad capitalization. That second directory was invisible in VS, but when I tracked it down manually I was able to delete it. After restarting VS code to force it to recognize the correct folder, I was able to get it working again.
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
I have the same issue, and just discovered that for some reason, in some ts file it is called using capitalize letter, then I renamed it for lowercase and it works. You can try also removing this model ts file and creating again with angular-CLI.
It's all about the path of files, make sure it is **case-sensitive**
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
I had a similar issue and solved it by closing the folder, then on the Recent workspaces list click More at the bottom, and from the list click the 'x' (remove) button to remove the workspace. Then, after loading the project's folder, it build normally. So probably there is some cache and that is probably one way to clear it.
It's all about the path of files, make sure it is **case-sensitive**
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
I had a similar issue and solved it by closing the folder, then on the Recent workspaces list click More at the bottom, and from the list click the 'x' (remove) button to remove the workspace. Then, after loading the project's folder, it build normally. So probably there is some cache and that is probably one way to clear it.
i had this issue and it was a directory name capitalization problem. i was importing my component like this : ``` ../proxies/test.component ../Proxies/test.component ```
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
i had this issue and it was a directory name capitalization problem. i was importing my component like this : ``` ../proxies/test.component ../Proxies/test.component ```
It's all about the path of files, make sure it is **case-sensitive**
54,114,923
I want to make a button in an activity disabled if it is intented from a certain button and otherwise enabled if and it is intented from some other class.What I am saying will be clear after reading the code. This is the function to intent the class containing the button. ``` showperson.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { falses=true; ob.truth=false; Toast.makeText(home_page.this, "doneit"+ob.truth, Toast.LENGTH_SHORT).show(); // Button clik=fb.getButton(); // clik.setVisibility(View.GONE); Intent to=new Intent(home_page.this,Form.class); to.putExtra("buttonclik",false); startActivity(to); } }); ```
2019/01/09
[ "https://Stackoverflow.com/questions/54114923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10841645/" ]
I have the same issue, and just discovered that for some reason, in some ts file it is called using capitalize letter, then I renamed it for lowercase and it works. You can try also removing this model ts file and creating again with angular-CLI.
In my case, when renaming the folder I made a capitalization error, then corrected it. Somehow, visual studio created a second directory with the bad capitalization. That second directory was invisible in VS, but when I tracked it down manually I was able to delete it. After restarting VS code to force it to recognize the correct folder, I was able to get it working again.
146,570
I am writing an app that requires multiple levels of users, where one user is an administrator and adds slave users. I can't really seem to find a way to allow access to the slave users safely. Emailing a password is unsafe as emails are unencrypted, and I might as well just send the password if I'm sending a one-time link. I can reduce the window exponentially by making a temporary password required to be changed on first login, emailing a one-time use link, setting a timeout on either of these, or any combination of all of these... But the window still seems extremely large compared to asynchronous encryption, for example. I could require an SSH communication or something, but obviously this is not even close to pragmatic. What is the industry standard, and what solution, if any, can provide both a pragmatic user-friendly experience, as well as a secure channel?
2016/12/27
[ "https://security.stackexchange.com/questions/146570", "https://security.stackexchange.com", "https://security.stackexchange.com/users/112167/" ]
Assuming you are talking about personal accounts not company accounts here. It's part of your identity and you should protect it as much as possible, risk is greater if they can find your address (fairly easy - online address finders, whois records if you own the website) or your date of birth. There was a case a few years ago where a UK celebrity claimed nothing could be done with their acct no / sort code and published them in the press - a stranger used their details to set up a direct debit to a charity. [link to source (BBC)](http://news.bbc.co.uk/1/hi/entertainment/7174760.stm) Although you might have a number of trusted customers - your details will be available to anyone who can get to your site and some of those may be malicious. If you are in the UK, the direct debit guarantee may cover you if any one set up anything like that but your bank may consider it reckless to post your details in public. I certainly would be very uncomfortable doing so and would consider a payment gateway instead.
I think I could pay my car payment with just that information. You could use PayPal for this kind of venture.
32,802,592
I'm developing an application that lets my users upload files, and I've made it works with "local" disk using filesystem feature, but now I want to migrate and use google Google Cloud Storage for it. It has been a lot difficult to find some useful information. In the docs there is an "example" for work with dropbox, but it's not complete. It doesn't shows how to config drivers and disk, so it isn't clear enough for me. I would like to know what to do, since I have no idea from now. I've just used this tutorial <http://www.codetutorial.io/laravel-5-file-upload-storage-download/> and it's working for local, so I really need to migrate to google cloud storage, and only that. I'm using openshift and I feel comfortable about it. Could you please help me to know what should I configure filesystem to be used as I need? Thank you
2015/09/26
[ "https://Stackoverflow.com/questions/32802592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2533782/" ]
I've found a solution. It seems that Google Cloud Storage uses the same api than Amazon S3, so I could use it as I would use amazon, the same driver. The only thing I needed to change was when I config disks in laravel, using this code in config/filesystems when adding a disk for google: ``` 'google' => [ 'driver' => 's3', 'key' => 'xxx', 'secret' => 'xxx', 'bucket' => 'qrnotesfiles', 'base_url'=>'https://storage.googleapis.com' ] ```
I didn't find solutions\adapters like [here](https://github.com/GrahamCampbell/Laravel-Flysystem) This is what i [found](https://stackoverflow.com/questions/24778296/use-google-drive-api-with-laravel/24798103#24798103) but it's for google drive.
18,227,090
I have a service that fetches some client data from my server: ``` app.factory('clientDataService', function ($http) { var clientDataObject = {}; var cdsService = { fetch: function (cid) { //$http returns a promise, which has a then function, which also returns a promise var promise = $http.get('/clients/stats/' + cid + '/').then(function (response) { // The then function here is an opportunity to modify the response console.log(response); // The return value gets picked up by the then in the controller. clientDataObject = {'data': response.data, 'currentClientID': cid}; return clientDataObject; }); // Return the promise to the controller return promise; } }; return cdsService; }); ``` Then in one controller I do: ``` //get stats clientDataService.fetch($scope.id).then(function (response) { $scope.client_data = { 'statistics': response.data } }); ``` Which all works very well. However, I'm trying to do a watch from another controller on that service to update it's scope when the data changes, rather then having to re-kick off the http request: ``` $scope.$watch('clientDataService.clientDataObject', function (cid) { alert(cid); }); ``` I'm just alerting for now, but it never ever triggers. When the page initially loads, it alerts "undefined". I have no errors in the console and all the $injects are fine, but it never seems to recognize that data has changed in the service. Am I doing something wrong in the watch? Many thanks Ben
2013/08/14
[ "https://Stackoverflow.com/questions/18227090", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1000654/" ]
clientDataService.clientDataObject is not part of your controller's scope, so you can't watch for changes on that object. You need to inject the $rootScope into your service then broadcast the changes to the controllers scopes. ``` app.factory('clientDataService', function ($rootScope, $http) { var clientDataObject = {}; var cdsService = { fetch: function (cid) { var promise = $http.get('/clients/stats/' + cid + '/').then(function (response) { // The then function here is an opportunity to modify the response console.log(response); // The return value gets picked up by the then in the controller. clientDataObject = {'data': response.data, 'currentClientID': cid}; $rootScope.$broadcast('UPDATE_CLIENT_DATA', clientDataObject); return clientDataObject; }); // Return the promise to the controller return promise; } }; return cdsService; }); ``` Then in the controller you can listen for the change using: ``` $scope.$on('UPDATE_CLIENT_DATA', function ( event, clientDataObject ) { }); ```
Another approach can be: 1. define new service ``` app.factory('DataSharingObject', function(){ return {}; } ``` 2. include this new service in controller where we want to store the data ``` app.factory('clientDataService', function ($http, DataSharingObject) { DataSharingObject.sharedata = ..assign it here } ``` 3. include this new service in controller where we want to access the data ``` app.factory('clientReceivingService', function ($http, DataSharingObject) { ..use it here... = DataSharingObject.sharedata } ```
29,885,786
In wordpress I have an article in my `content.php` which creates a grid of images out of the `featured-thumbnail` of posts. This snippet of code puts the post title `(the_title();)` and the category title `(the_category(', '))` **HTML**: ``` <div class="title-styling"> <a href="<?php the_permalink(); ?>" rel="bookmark"><h1><?php the_title(); ?></h1></a> <a href="<?php the_permalink(); ?> "><h2><?php the_category(', '); ?></h2></a> </div> ``` I want to target the css attributes of `the_category(', ')` text like change colour padding etc. But my CSS doesn't seem to affect it (especially colour), even with `!important` added. **CSS** (attempts that did not work): ``` .title-styling > h2 { color: #fff; font: 500 15px/10px "Open Sans"; } .title-styling h2 { color: #fff; font: 500 15px/10px "Open Sans"; } ```
2015/04/27
[ "https://Stackoverflow.com/questions/29885786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3550879/" ]
Try using the following ``` .title-styling > a > h2.title-category { color: #fff; font: 500 15px/10px "Open Sans"; } ``` And this if you want to remove the underline of the anchor tag (link) **[optional]** ``` .title-styling > a { text-decoration: none; } ``` **UPDATE:** Try giving a class to the h2 tag to target it more specifically ``` <div class="title-styling"> <a href="<?php the_permalink(); ?>" rel="bookmark"><h1><?php the_title(); ?></h1></a> <a href="<?php the_permalink(); ?> "><h2 class="title-category"><?php the_category(', '); ?></h2></a> </div> ```
> > represent it parent must .title-styling > > > try below: ``` .title-styling h2 { color: #fff; font: 500 15px/10px "Open Sans"; } ```
1,737,416
Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I'm actually using Kohana). I'm new to MVC and don't want to get this wrong... so I'm wondering if i have tables: ``` categories, pages, notes ``` I create a separate controller and view for each one...? So people can go to ``` /category/# /page/# /note/# ``` But then lets say I want to also be able to display multiple notes per page, it would be bad to call the note view in a loop from the page view. So should I create some kind of a function that draws the notes and pass variables to that function from the note view and from a loop in the page view? Would this be the best way to go about it, if not how else should I do it...? Thanks, Serhiy
2009/11/15
[ "https://Stackoverflow.com/questions/1737416", "https://Stackoverflow.com", "https://Stackoverflow.com/users/156749/" ]
Yes, instead of just passing 1 entity (category, page, note) to your view, pass a list of entities. With a loop inside the view, you can display the whole list. That view may call another one (or a function) that know how to display one entry.
1. You can loop in the View. The View is allowed can also access the model in MVC. See: <http://www.phpwact.org/pattern/model_view_controller> 2. You don't need to have a controller (or model) for each table.
1,737,416
Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I'm actually using Kohana). I'm new to MVC and don't want to get this wrong... so I'm wondering if i have tables: ``` categories, pages, notes ``` I create a separate controller and view for each one...? So people can go to ``` /category/# /page/# /note/# ``` But then lets say I want to also be able to display multiple notes per page, it would be bad to call the note view in a loop from the page view. So should I create some kind of a function that draws the notes and pass variables to that function from the note view and from a loop in the page view? Would this be the best way to go about it, if not how else should I do it...? Thanks, Serhiy
2009/11/15
[ "https://Stackoverflow.com/questions/1737416", "https://Stackoverflow.com", "https://Stackoverflow.com/users/156749/" ]
I would personally have a "show" method for one item and a "list" method for multiple. In your controller you can say something like `$page_data['note'] = get_note(cat_id,page_id)` for the "show" method and `$page_data['notes'] = get_all_notes(cat_id)` for the "list" method. Then in your view, you loop over the `$page_data['notes']` and display HTML for each one. If the list view is using the same "note" HTML as the "show" view, create a template or function to spit out the HTML given a note: ``` // In your "list" view foreach($n in $page_data['notes']){ print_note_html($n) } //In your "show" view print_note_html($n) ``` The `print_note_html` function can be a helper method accessible by all views for Notes. Make sense?
1. You can loop in the View. The View is allowed can also access the model in MVC. See: <http://www.phpwact.org/pattern/model_view_controller> 2. You don't need to have a controller (or model) for each table.
1,737,416
Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I'm actually using Kohana). I'm new to MVC and don't want to get this wrong... so I'm wondering if i have tables: ``` categories, pages, notes ``` I create a separate controller and view for each one...? So people can go to ``` /category/# /page/# /note/# ``` But then lets say I want to also be able to display multiple notes per page, it would be bad to call the note view in a loop from the page view. So should I create some kind of a function that draws the notes and pass variables to that function from the note view and from a loop in the page view? Would this be the best way to go about it, if not how else should I do it...? Thanks, Serhiy
2009/11/15
[ "https://Stackoverflow.com/questions/1737416", "https://Stackoverflow.com", "https://Stackoverflow.com/users/156749/" ]
Yes, instead of just passing 1 entity (category, page, note) to your view, pass a list of entities. With a loop inside the view, you can display the whole list. That view may call another one (or a function) that know how to display one entry.
I would personally have a "show" method for one item and a "list" method for multiple. In your controller you can say something like `$page_data['note'] = get_note(cat_id,page_id)` for the "show" method and `$page_data['notes'] = get_all_notes(cat_id)` for the "list" method. Then in your view, you loop over the `$page_data['notes']` and display HTML for each one. If the list view is using the same "note" HTML as the "show" view, create a template or function to spit out the HTML given a note: ``` // In your "list" view foreach($n in $page_data['notes']){ print_note_html($n) } //In your "show" view print_note_html($n) ``` The `print_note_html` function can be a helper method accessible by all views for Notes. Make sense?
1,737,416
Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I'm actually using Kohana). I'm new to MVC and don't want to get this wrong... so I'm wondering if i have tables: ``` categories, pages, notes ``` I create a separate controller and view for each one...? So people can go to ``` /category/# /page/# /note/# ``` But then lets say I want to also be able to display multiple notes per page, it would be bad to call the note view in a loop from the page view. So should I create some kind of a function that draws the notes and pass variables to that function from the note view and from a loop in the page view? Would this be the best way to go about it, if not how else should I do it...? Thanks, Serhiy
2009/11/15
[ "https://Stackoverflow.com/questions/1737416", "https://Stackoverflow.com", "https://Stackoverflow.com/users/156749/" ]
Yes, instead of just passing 1 entity (category, page, note) to your view, pass a list of entities. With a loop inside the view, you can display the whole list. That view may call another one (or a function) that know how to display one entry.
In CodeIgniter I create a separate helper file where I put functions that return the markup for UI elements that may need to be included multiple times in the one view. In your example, I would create a function to return the markup for a note. **application/helpers/view\_helper.php** ``` function note($note) { return '<div class="note">' . '<h2>' . $note->title . '</h2>' . '<p>' . $note->contents . '</p></div>'; } ``` I would normally auto-load this helper file. And then in the view I would do something like this. ``` echo note($note); ``` For a list of notes in a view, I would iterate the list calling this function. ``` <div class="note-list"> <?php foreach ($notes as $note) : ?> <?php echo note($note); ?> <?php endforeach; ?> </div> ``` I found that including a view many times in another view was slow. Thats why I did it this way. **Edit** I just dug into the CodeIgniter Loader class and sure enough a PHP include is being done every time you call ``` $this->load->view('view_name'); ``` This means that if you use this method to display a list of 20 notes, you're going to be doing 20 separate includes.
1,737,416
Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I'm actually using Kohana). I'm new to MVC and don't want to get this wrong... so I'm wondering if i have tables: ``` categories, pages, notes ``` I create a separate controller and view for each one...? So people can go to ``` /category/# /page/# /note/# ``` But then lets say I want to also be able to display multiple notes per page, it would be bad to call the note view in a loop from the page view. So should I create some kind of a function that draws the notes and pass variables to that function from the note view and from a loop in the page view? Would this be the best way to go about it, if not how else should I do it...? Thanks, Serhiy
2009/11/15
[ "https://Stackoverflow.com/questions/1737416", "https://Stackoverflow.com", "https://Stackoverflow.com/users/156749/" ]
I would personally have a "show" method for one item and a "list" method for multiple. In your controller you can say something like `$page_data['note'] = get_note(cat_id,page_id)` for the "show" method and `$page_data['notes'] = get_all_notes(cat_id)` for the "list" method. Then in your view, you loop over the `$page_data['notes']` and display HTML for each one. If the list view is using the same "note" HTML as the "show" view, create a template or function to spit out the HTML given a note: ``` // In your "list" view foreach($n in $page_data['notes']){ print_note_html($n) } //In your "show" view print_note_html($n) ``` The `print_note_html` function can be a helper method accessible by all views for Notes. Make sense?
In CodeIgniter I create a separate helper file where I put functions that return the markup for UI elements that may need to be included multiple times in the one view. In your example, I would create a function to return the markup for a note. **application/helpers/view\_helper.php** ``` function note($note) { return '<div class="note">' . '<h2>' . $note->title . '</h2>' . '<p>' . $note->contents . '</p></div>'; } ``` I would normally auto-load this helper file. And then in the view I would do something like this. ``` echo note($note); ``` For a list of notes in a view, I would iterate the list calling this function. ``` <div class="note-list"> <?php foreach ($notes as $note) : ?> <?php echo note($note); ?> <?php endforeach; ?> </div> ``` I found that including a view many times in another view was slow. Thats why I did it this way. **Edit** I just dug into the CodeIgniter Loader class and sure enough a PHP include is being done every time you call ``` $this->load->view('view_name'); ``` This means that if you use this method to display a list of 20 notes, you're going to be doing 20 separate includes.
58,091,848
Trying to create a socketio link between flask server and reactjs client. It shows this error "Access to XMLHttpRequest at '<http://127.0.0.1:5000/socket.io/?EIO=3&transport=polling&t=MrcruFC>' from origin '<http://localhost:3000>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource." I have tried including CORS from the flask cors documentation but it still doesnot work. Server: ``` from flask import Flask, Response from flask_cors import CORS from flask_socketio import SocketIO app = Flask(__name__) cors = CORS(app) socketio=SocketIO(app) @socketio.on('connection') def handle_my_custom_event(): socket.emit('outgoing data',{num: '10'}) @app.route("/") def hello(): return 'Hello' if __name__ == '__main__': socketio.run(app, host='0.0.0.0', port=5000) ```
2019/09/25
[ "https://Stackoverflow.com/questions/58091848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12057928/" ]
You can add an option for creating SocketIO. ``` socketio = SocketIO(app=app, cors_allowed_origins='*') ```
You can allow the CORS using the following headers: ```py header = response.headers header['Access-Control-Allow-Origin'] = '*' ```
5,081,640
Dear experts, I am currently working on an code that allows users to drag & resize HTML elements across the pages. I could tackle the draggable no problem. But the problem comes from resizing. I don't know how attach Event Listeners to the "borders" of this elements to trigger the resize, specifically only the "right and bottom" borders. I am aware of the similar approach on the Jquery UI, but I do not want to use the Jquery UI. I would like to do it myself with vanilla Javascript and Jquery API. I have spent the whole day searching on Google for a proper tutorial but failed. If you could point me to the right direction I would really appreciate. Dennis
2011/02/22
[ "https://Stackoverflow.com/questions/5081640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/291051/" ]
jquery ui appends 8 elements on top of your draggable element. south, southwest, west... and so on. Is it what you meant?
How do users resize them without dragging? if they just input a number have you tried the following ``` $(element).width(widthInput); $(element).height(heightInput); ```
7,699,870
Hi I have turned on buffer cycling placing following commands in my .emacs ``` (global-set-key (kbd "<C-tab>") 'bury-buffer) ``` But while cycling how do I avoid cycling through the Messages and the scrratch buffers which are always present in any emacs buffer list. I never use those buffers and become an eye-sore when cycling through my buffer-list
2011/10/08
[ "https://Stackoverflow.com/questions/7699870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/505306/" ]
If you never use the scratch buffer, just add this to your .emacs to automatically close it: > > (kill-buffer "\*scratch\*") > > > I also found [this code](http://www.emacswiki.org/emacs/ControlTABbufferCycling#toc3) on the [Emacs wiki](http://www.emacswiki.org/) which should do what you want: ``` ; necessary support function for buffer burial (defun crs-delete-these (delete-these from-this-list) "Delete DELETE-THESE FROM-THIS-LIST." (cond ((car delete-these) (if (member (car delete-these) from-this-list) (crs-delete-these (cdr delete-these) (delete (car delete-these) from-this-list)) (crs-delete-these (cdr delete-these) from-this-list))) (t from-this-list))) ; this is the list of buffers I never want to see (defvar crs-hated-buffers '("KILL" "*Compile-Log*")) ; might as well use this for both (setq iswitchb-buffer-ignore (append '("^ " "*Buffer") crs-hated-buffers)) (defun crs-hated-buffers () "List of buffers I never want to see, converted from names to buffers." (delete nil (append (mapcar 'get-buffer crs-hated-buffers) (mapcar (lambda (this-buffer) (if (string-match "^ " (buffer-name this-buffer)) this-buffer)) (buffer-list))))) ; I'm sick of switching buffers only to find KILL right in front of me (defun crs-bury-buffer (&optional n) (interactive) (unless n (setq n 1)) (let ((my-buffer-list (crs-delete-these (crs-hated-buffers) (buffer-list (selected-frame))))) (switch-to-buffer (if (< n 0) (nth (+ (length my-buffer-list) n) my-buffer-list) (bury-buffer) (nth n my-buffer-list))))) (global-set-key [(control tab)] 'crs-bury-buffer) (global-set-key [(control meta tab)] (lambda () (interactive) (crs-bury-buffer -1))) ``` You will need to add the scratch and message buffers to the variable `crs-hated-buffers`, e.g.: ``` (add-to-list 'crs-hated-buffers "*Messages*") (add-to-list 'crs-hated-buffers "*scratch*") ```
Luke's answered your specific question. In my personal experience buffer cycling is more useful as a most-recently-used stack instead of the Emacs default cycling functions. That is, the buffers you most recently used should bubble to the top of the stack, similar to how alt-tab works in Windows. There are quite a few packages that implement this on the [wiki](http://www.emacswiki.org/emacs/ControlTABbufferCycling#toc1). `buffer-stack` is the one I recommend. It has a list of excluded buffers by default, I've included my `buffer-stack-suppl` configuration, which does same major-mode filtering. If you ask questions about `buffer-stack`, I'll try my best to help.
7,699,870
Hi I have turned on buffer cycling placing following commands in my .emacs ``` (global-set-key (kbd "<C-tab>") 'bury-buffer) ``` But while cycling how do I avoid cycling through the Messages and the scrratch buffers which are always present in any emacs buffer list. I never use those buffers and become an eye-sore when cycling through my buffer-list
2011/10/08
[ "https://Stackoverflow.com/questions/7699870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/505306/" ]
If you never use the scratch buffer, just add this to your .emacs to automatically close it: > > (kill-buffer "\*scratch\*") > > > I also found [this code](http://www.emacswiki.org/emacs/ControlTABbufferCycling#toc3) on the [Emacs wiki](http://www.emacswiki.org/) which should do what you want: ``` ; necessary support function for buffer burial (defun crs-delete-these (delete-these from-this-list) "Delete DELETE-THESE FROM-THIS-LIST." (cond ((car delete-these) (if (member (car delete-these) from-this-list) (crs-delete-these (cdr delete-these) (delete (car delete-these) from-this-list)) (crs-delete-these (cdr delete-these) from-this-list))) (t from-this-list))) ; this is the list of buffers I never want to see (defvar crs-hated-buffers '("KILL" "*Compile-Log*")) ; might as well use this for both (setq iswitchb-buffer-ignore (append '("^ " "*Buffer") crs-hated-buffers)) (defun crs-hated-buffers () "List of buffers I never want to see, converted from names to buffers." (delete nil (append (mapcar 'get-buffer crs-hated-buffers) (mapcar (lambda (this-buffer) (if (string-match "^ " (buffer-name this-buffer)) this-buffer)) (buffer-list))))) ; I'm sick of switching buffers only to find KILL right in front of me (defun crs-bury-buffer (&optional n) (interactive) (unless n (setq n 1)) (let ((my-buffer-list (crs-delete-these (crs-hated-buffers) (buffer-list (selected-frame))))) (switch-to-buffer (if (< n 0) (nth (+ (length my-buffer-list) n) my-buffer-list) (bury-buffer) (nth n my-buffer-list))))) (global-set-key [(control tab)] 'crs-bury-buffer) (global-set-key [(control meta tab)] (lambda () (interactive) (crs-bury-buffer -1))) ``` You will need to add the scratch and message buffers to the variable `crs-hated-buffers`, e.g.: ``` (add-to-list 'crs-hated-buffers "*Messages*") (add-to-list 'crs-hated-buffers "*scratch*") ```
Well, if you use `ido-mode` to cycle between buffers you can set `ido-ignore-buffers` to match the buffers you want to ignore. From the documentation: > > List of regexps or functions matching buffer names to ignore. > For example, traditional behavior is not to list buffers whose names begin > with a space, for which the regexp is "` ". See the source file for > example functions that filter buffer names. > > > For more info on `ido-mode` see: [Introduction to ido-mode](http://www.masteringemacs.org/articles/2010/10/10/introduction-to-ido-mode/)
7,699,870
Hi I have turned on buffer cycling placing following commands in my .emacs ``` (global-set-key (kbd "<C-tab>") 'bury-buffer) ``` But while cycling how do I avoid cycling through the Messages and the scrratch buffers which are always present in any emacs buffer list. I never use those buffers and become an eye-sore when cycling through my buffer-list
2011/10/08
[ "https://Stackoverflow.com/questions/7699870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/505306/" ]
If you never use the scratch buffer, just add this to your .emacs to automatically close it: > > (kill-buffer "\*scratch\*") > > > I also found [this code](http://www.emacswiki.org/emacs/ControlTABbufferCycling#toc3) on the [Emacs wiki](http://www.emacswiki.org/) which should do what you want: ``` ; necessary support function for buffer burial (defun crs-delete-these (delete-these from-this-list) "Delete DELETE-THESE FROM-THIS-LIST." (cond ((car delete-these) (if (member (car delete-these) from-this-list) (crs-delete-these (cdr delete-these) (delete (car delete-these) from-this-list)) (crs-delete-these (cdr delete-these) from-this-list))) (t from-this-list))) ; this is the list of buffers I never want to see (defvar crs-hated-buffers '("KILL" "*Compile-Log*")) ; might as well use this for both (setq iswitchb-buffer-ignore (append '("^ " "*Buffer") crs-hated-buffers)) (defun crs-hated-buffers () "List of buffers I never want to see, converted from names to buffers." (delete nil (append (mapcar 'get-buffer crs-hated-buffers) (mapcar (lambda (this-buffer) (if (string-match "^ " (buffer-name this-buffer)) this-buffer)) (buffer-list))))) ; I'm sick of switching buffers only to find KILL right in front of me (defun crs-bury-buffer (&optional n) (interactive) (unless n (setq n 1)) (let ((my-buffer-list (crs-delete-these (crs-hated-buffers) (buffer-list (selected-frame))))) (switch-to-buffer (if (< n 0) (nth (+ (length my-buffer-list) n) my-buffer-list) (bury-buffer) (nth n my-buffer-list))))) (global-set-key [(control tab)] 'crs-bury-buffer) (global-set-key [(control meta tab)] (lambda () (interactive) (crs-bury-buffer -1))) ``` You will need to add the scratch and message buffers to the variable `crs-hated-buffers`, e.g.: ``` (add-to-list 'crs-hated-buffers "*Messages*") (add-to-list 'crs-hated-buffers "*scratch*") ```
All the buffers I did not use, such as scratch, messages and completions, messed with my workflow. I've managed to completely get rid of them, without breaking emacs in any way. Posted first [here](https://unix.stackexchange.com/a/152151/72170), and pasted bellow: Place this in your .emacs: ``` ;; Makes *scratch* empty. (setq initial-scratch-message "") ;; Removes *scratch* from buffer after the mode has been set. (defun remove-scratch-buffer () (if (get-buffer "*scratch*") (kill-buffer "*scratch*"))) (add-hook 'after-change-major-mode-hook 'remove-scratch-buffer) ;; Removes *messages* from the buffer. (setq-default message-log-max nil) (kill-buffer "*Messages*") ;; Removes *Completions* from buffer after you've opened a file. (add-hook 'minibuffer-exit-hook '(lambda () (let ((buffer "*Completions*")) (and (get-buffer buffer) (kill-buffer buffer))))) ;; Don't show *Buffer list* when opening multiple files at the same time. (setq inhibit-startup-buffer-menu t) ;; Show only one active window when opening multiple files at the same time. (add-hook 'window-setup-hook 'delete-other-windows) ``` Bonus: ``` ;; No more typing the whole yes or no. Just y or n will do. (fset 'yes-or-no-p 'y-or-n-p) ```
7,699,870
Hi I have turned on buffer cycling placing following commands in my .emacs ``` (global-set-key (kbd "<C-tab>") 'bury-buffer) ``` But while cycling how do I avoid cycling through the Messages and the scrratch buffers which are always present in any emacs buffer list. I never use those buffers and become an eye-sore when cycling through my buffer-list
2011/10/08
[ "https://Stackoverflow.com/questions/7699870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/505306/" ]
Luke's answered your specific question. In my personal experience buffer cycling is more useful as a most-recently-used stack instead of the Emacs default cycling functions. That is, the buffers you most recently used should bubble to the top of the stack, similar to how alt-tab works in Windows. There are quite a few packages that implement this on the [wiki](http://www.emacswiki.org/emacs/ControlTABbufferCycling#toc1). `buffer-stack` is the one I recommend. It has a list of excluded buffers by default, I've included my `buffer-stack-suppl` configuration, which does same major-mode filtering. If you ask questions about `buffer-stack`, I'll try my best to help.
Well, if you use `ido-mode` to cycle between buffers you can set `ido-ignore-buffers` to match the buffers you want to ignore. From the documentation: > > List of regexps or functions matching buffer names to ignore. > For example, traditional behavior is not to list buffers whose names begin > with a space, for which the regexp is "` ". See the source file for > example functions that filter buffer names. > > > For more info on `ido-mode` see: [Introduction to ido-mode](http://www.masteringemacs.org/articles/2010/10/10/introduction-to-ido-mode/)
7,699,870
Hi I have turned on buffer cycling placing following commands in my .emacs ``` (global-set-key (kbd "<C-tab>") 'bury-buffer) ``` But while cycling how do I avoid cycling through the Messages and the scrratch buffers which are always present in any emacs buffer list. I never use those buffers and become an eye-sore when cycling through my buffer-list
2011/10/08
[ "https://Stackoverflow.com/questions/7699870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/505306/" ]
Luke's answered your specific question. In my personal experience buffer cycling is more useful as a most-recently-used stack instead of the Emacs default cycling functions. That is, the buffers you most recently used should bubble to the top of the stack, similar to how alt-tab works in Windows. There are quite a few packages that implement this on the [wiki](http://www.emacswiki.org/emacs/ControlTABbufferCycling#toc1). `buffer-stack` is the one I recommend. It has a list of excluded buffers by default, I've included my `buffer-stack-suppl` configuration, which does same major-mode filtering. If you ask questions about `buffer-stack`, I'll try my best to help.
All the buffers I did not use, such as scratch, messages and completions, messed with my workflow. I've managed to completely get rid of them, without breaking emacs in any way. Posted first [here](https://unix.stackexchange.com/a/152151/72170), and pasted bellow: Place this in your .emacs: ``` ;; Makes *scratch* empty. (setq initial-scratch-message "") ;; Removes *scratch* from buffer after the mode has been set. (defun remove-scratch-buffer () (if (get-buffer "*scratch*") (kill-buffer "*scratch*"))) (add-hook 'after-change-major-mode-hook 'remove-scratch-buffer) ;; Removes *messages* from the buffer. (setq-default message-log-max nil) (kill-buffer "*Messages*") ;; Removes *Completions* from buffer after you've opened a file. (add-hook 'minibuffer-exit-hook '(lambda () (let ((buffer "*Completions*")) (and (get-buffer buffer) (kill-buffer buffer))))) ;; Don't show *Buffer list* when opening multiple files at the same time. (setq inhibit-startup-buffer-menu t) ;; Show only one active window when opening multiple files at the same time. (add-hook 'window-setup-hook 'delete-other-windows) ``` Bonus: ``` ;; No more typing the whole yes or no. Just y or n will do. (fset 'yes-or-no-p 'y-or-n-p) ```
7,699,870
Hi I have turned on buffer cycling placing following commands in my .emacs ``` (global-set-key (kbd "<C-tab>") 'bury-buffer) ``` But while cycling how do I avoid cycling through the Messages and the scrratch buffers which are always present in any emacs buffer list. I never use those buffers and become an eye-sore when cycling through my buffer-list
2011/10/08
[ "https://Stackoverflow.com/questions/7699870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/505306/" ]
All the buffers I did not use, such as scratch, messages and completions, messed with my workflow. I've managed to completely get rid of them, without breaking emacs in any way. Posted first [here](https://unix.stackexchange.com/a/152151/72170), and pasted bellow: Place this in your .emacs: ``` ;; Makes *scratch* empty. (setq initial-scratch-message "") ;; Removes *scratch* from buffer after the mode has been set. (defun remove-scratch-buffer () (if (get-buffer "*scratch*") (kill-buffer "*scratch*"))) (add-hook 'after-change-major-mode-hook 'remove-scratch-buffer) ;; Removes *messages* from the buffer. (setq-default message-log-max nil) (kill-buffer "*Messages*") ;; Removes *Completions* from buffer after you've opened a file. (add-hook 'minibuffer-exit-hook '(lambda () (let ((buffer "*Completions*")) (and (get-buffer buffer) (kill-buffer buffer))))) ;; Don't show *Buffer list* when opening multiple files at the same time. (setq inhibit-startup-buffer-menu t) ;; Show only one active window when opening multiple files at the same time. (add-hook 'window-setup-hook 'delete-other-windows) ``` Bonus: ``` ;; No more typing the whole yes or no. Just y or n will do. (fset 'yes-or-no-p 'y-or-n-p) ```
Well, if you use `ido-mode` to cycle between buffers you can set `ido-ignore-buffers` to match the buffers you want to ignore. From the documentation: > > List of regexps or functions matching buffer names to ignore. > For example, traditional behavior is not to list buffers whose names begin > with a space, for which the regexp is "` ". See the source file for > example functions that filter buffer names. > > > For more info on `ido-mode` see: [Introduction to ido-mode](http://www.masteringemacs.org/articles/2010/10/10/introduction-to-ido-mode/)
34,653,103
``` @ECHO OFF :Start SET /P Enter user name: SET /P Enter Password: SET /P Enter age: SET /p Enter Passeword: ``` For the given above .bat file . How do I pass arguments using PYTHON I want to write Python automation script which call the batch file and pass the required argument in the batch file
2016/01/07
[ "https://Stackoverflow.com/questions/34653103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653130/" ]
Its important to hide session ID for MITMA but of accessibility you need it to let web sites know who you are and what was your last activity. The technique which is widely used is limited time session ID
What would be the benefit of encrypting or masking it? Assuming there were an uncomplicated and non-timewasting way to do this, an attacker only need copy the encrypted form of the token and feed it to your application and your application will dutifully decrypt it, regardless of the source. Ditto for masking it: whatever masking you perform before transporting it, means that some component on the server side will need to unmask it to make it usable. So really, you're not going to achieve anything in the direction you're looking at. The major viable threat here is a session-replay attack, which can easily be mitigated by ensuring that 1. Your sessions don't live for too long 2. You implement a single active session policy, where any given user id cannot have more than one active session - meaning that even if a session ID were compromised, no new session can be started with the stolen token. If you're that concerned with the handling of session tokens, you should read through [OWASP's session management article](https://www.owasp.org/index.php/Session_Management) that will give you better practice in protecting your sessions; what you're looking at now is just distracting
8,272,897
I have a `ListActivity`, where I need to show a image and text in every row. The `event.xml` layout looks like this: ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_height="wrap_content" android:layout_width="30px" android:layout_marginTop="2px" android:layout_marginRight="2px" android:layout_marginLeft="2px" android:id="@+id/logoImage"> </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title" android:textSize="15px"></TextView> </LinearLayout> ``` The activity looks like this: ``` public class Activity extends ListActivity{ public void onCreate(Bundle icicle) { super.onCreate(icicle); dba=new DatabaseAdapter(this); dba.open(); View header = getLayoutInflater().inflate(R.layout.header, null); ListView lv = getListView(); lv.addHeaderView(header); fillOnStart(); } private void fillOnStart(){ ArrayList<Title> temp = dba.returnTitle(); // this works ArrAdapter notes = new ArrAdapter(this, temp); Toast.makeText(this, "Size: " +notes.getCount(), Toast.LENGTH_LONG).show(); //because this show good size setListAdapter(notes); } ``` and my adapter looks like this: ``` private class ArrAdapter extends BaseAdapter{ private Context mContext; private ArrayList<Title> lista; public ArrAdapter(Context c, ArrayList<Title> list){ mContext = c; this.lista =list; } public int getCount() { // TODO Auto-generated method stub return lista.size(); } public Object getItem(int position) { // TODO Auto-generated method stub return position; } public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // ViewHolder vh =null; Title title= lista.get(position); LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.event, parent, false); ImageView imlogo = (ImageView)v.findViewById(R.id.logoImage); TextView textTitle = (TextView)v.findViewById(R.id.title); imlogo.setImageResource(title.getLogo()); textTitle.setText(title.getTit()); return v; } } ``` class title looks like: ``` public class Title { public int id; public String tit; public Bitmap logo; public Bitmap getLogo() { return logo; } ... and other setter and getter } ``` and method returns Arraylist (in dba) with Title look like that: ``` public ArrayList<Title> returnTitle(){ Title t = new Title(1,"aaaaaaaaaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\favicon.ico")); Title t1 = new Title(2,"assdsdsdsdaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\icon.ico")); ArrayList<Title> art = new ArrayList<Title>(2); art.add(t); art.add(t1); return art; } ``` My List activity shows me only text. What I must change to see a image with text?
2011/11/25
[ "https://Stackoverflow.com/questions/8272897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1055201/" ]
By definition: http status code 503: Service Unavailable. The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state. As 500-599 present a server side error, happening all the time, on Web service or Web site. For 503, slowing down the frequency of the requests from your client program is a good way to go, and you might need to consider UI design as well if your client program has GUI>
How about a TTimer? That way your app isn't locked up with a sleep() call.
8,272,897
I have a `ListActivity`, where I need to show a image and text in every row. The `event.xml` layout looks like this: ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_height="wrap_content" android:layout_width="30px" android:layout_marginTop="2px" android:layout_marginRight="2px" android:layout_marginLeft="2px" android:id="@+id/logoImage"> </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title" android:textSize="15px"></TextView> </LinearLayout> ``` The activity looks like this: ``` public class Activity extends ListActivity{ public void onCreate(Bundle icicle) { super.onCreate(icicle); dba=new DatabaseAdapter(this); dba.open(); View header = getLayoutInflater().inflate(R.layout.header, null); ListView lv = getListView(); lv.addHeaderView(header); fillOnStart(); } private void fillOnStart(){ ArrayList<Title> temp = dba.returnTitle(); // this works ArrAdapter notes = new ArrAdapter(this, temp); Toast.makeText(this, "Size: " +notes.getCount(), Toast.LENGTH_LONG).show(); //because this show good size setListAdapter(notes); } ``` and my adapter looks like this: ``` private class ArrAdapter extends BaseAdapter{ private Context mContext; private ArrayList<Title> lista; public ArrAdapter(Context c, ArrayList<Title> list){ mContext = c; this.lista =list; } public int getCount() { // TODO Auto-generated method stub return lista.size(); } public Object getItem(int position) { // TODO Auto-generated method stub return position; } public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // ViewHolder vh =null; Title title= lista.get(position); LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.event, parent, false); ImageView imlogo = (ImageView)v.findViewById(R.id.logoImage); TextView textTitle = (TextView)v.findViewById(R.id.title); imlogo.setImageResource(title.getLogo()); textTitle.setText(title.getTit()); return v; } } ``` class title looks like: ``` public class Title { public int id; public String tit; public Bitmap logo; public Bitmap getLogo() { return logo; } ... and other setter and getter } ``` and method returns Arraylist (in dba) with Title look like that: ``` public ArrayList<Title> returnTitle(){ Title t = new Title(1,"aaaaaaaaaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\favicon.ico")); Title t1 = new Title(2,"assdsdsdsdaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\icon.ico")); ArrayList<Title> art = new ArrayList<Title>(2); art.add(t); art.add(t1); return art; } ``` My List activity shows me only text. What I must change to see a image with text?
2011/11/25
[ "https://Stackoverflow.com/questions/8272897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1055201/" ]
To handle a temorary error like 503, the message processing queue could use an incrementing delay time, a failed request will increase the waiting time (up to a defined maximum). If a request was successful, the delay is reset. So I would for example start with a 500 msec interval. Every time the request fails, the interval will be multiplied by two up to a maximum delay of 16 seconds. If a request returns without error, the interval is reset to its initial value of 500 msec.
How about a TTimer? That way your app isn't locked up with a sleep() call.
8,272,897
I have a `ListActivity`, where I need to show a image and text in every row. The `event.xml` layout looks like this: ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_height="wrap_content" android:layout_width="30px" android:layout_marginTop="2px" android:layout_marginRight="2px" android:layout_marginLeft="2px" android:id="@+id/logoImage"> </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title" android:textSize="15px"></TextView> </LinearLayout> ``` The activity looks like this: ``` public class Activity extends ListActivity{ public void onCreate(Bundle icicle) { super.onCreate(icicle); dba=new DatabaseAdapter(this); dba.open(); View header = getLayoutInflater().inflate(R.layout.header, null); ListView lv = getListView(); lv.addHeaderView(header); fillOnStart(); } private void fillOnStart(){ ArrayList<Title> temp = dba.returnTitle(); // this works ArrAdapter notes = new ArrAdapter(this, temp); Toast.makeText(this, "Size: " +notes.getCount(), Toast.LENGTH_LONG).show(); //because this show good size setListAdapter(notes); } ``` and my adapter looks like this: ``` private class ArrAdapter extends BaseAdapter{ private Context mContext; private ArrayList<Title> lista; public ArrAdapter(Context c, ArrayList<Title> list){ mContext = c; this.lista =list; } public int getCount() { // TODO Auto-generated method stub return lista.size(); } public Object getItem(int position) { // TODO Auto-generated method stub return position; } public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // ViewHolder vh =null; Title title= lista.get(position); LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.event, parent, false); ImageView imlogo = (ImageView)v.findViewById(R.id.logoImage); TextView textTitle = (TextView)v.findViewById(R.id.title); imlogo.setImageResource(title.getLogo()); textTitle.setText(title.getTit()); return v; } } ``` class title looks like: ``` public class Title { public int id; public String tit; public Bitmap logo; public Bitmap getLogo() { return logo; } ... and other setter and getter } ``` and method returns Arraylist (in dba) with Title look like that: ``` public ArrayList<Title> returnTitle(){ Title t = new Title(1,"aaaaaaaaaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\favicon.ico")); Title t1 = new Title(2,"assdsdsdsdaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\icon.ico")); ArrayList<Title> art = new ArrayList<Title>(2); art.add(t); art.add(t1); return art; } ``` My List activity shows me only text. What I must change to see a image with text?
2011/11/25
[ "https://Stackoverflow.com/questions/8272897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1055201/" ]
How about a TTimer? That way your app isn't locked up with a sleep() call.
I'm answering my own question. I won't accept it yet because this is only in concept stage. I think I'll create a common stack for all calls to services belonging to my provider. Every time a call is made, I'll set up a 'cool down' period using some form of thread or timer (I'm tempted to use this as an excuse to include [gabr](https://stackoverflow.com/users/4997/gabr)'s [OmniThread](http://otl.17slon.com/) library in my application.) So if two or more requests are submitted during the cool down period, I can chain them and show some fancy (\*) user interface to the user to avoid event breakage. If somebody has a better alternative, I'm all ears. *(\*): A dialog box with a progress bar, of course.*
8,272,897
I have a `ListActivity`, where I need to show a image and text in every row. The `event.xml` layout looks like this: ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_height="wrap_content" android:layout_width="30px" android:layout_marginTop="2px" android:layout_marginRight="2px" android:layout_marginLeft="2px" android:id="@+id/logoImage"> </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title" android:textSize="15px"></TextView> </LinearLayout> ``` The activity looks like this: ``` public class Activity extends ListActivity{ public void onCreate(Bundle icicle) { super.onCreate(icicle); dba=new DatabaseAdapter(this); dba.open(); View header = getLayoutInflater().inflate(R.layout.header, null); ListView lv = getListView(); lv.addHeaderView(header); fillOnStart(); } private void fillOnStart(){ ArrayList<Title> temp = dba.returnTitle(); // this works ArrAdapter notes = new ArrAdapter(this, temp); Toast.makeText(this, "Size: " +notes.getCount(), Toast.LENGTH_LONG).show(); //because this show good size setListAdapter(notes); } ``` and my adapter looks like this: ``` private class ArrAdapter extends BaseAdapter{ private Context mContext; private ArrayList<Title> lista; public ArrAdapter(Context c, ArrayList<Title> list){ mContext = c; this.lista =list; } public int getCount() { // TODO Auto-generated method stub return lista.size(); } public Object getItem(int position) { // TODO Auto-generated method stub return position; } public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // ViewHolder vh =null; Title title= lista.get(position); LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.event, parent, false); ImageView imlogo = (ImageView)v.findViewById(R.id.logoImage); TextView textTitle = (TextView)v.findViewById(R.id.title); imlogo.setImageResource(title.getLogo()); textTitle.setText(title.getTit()); return v; } } ``` class title looks like: ``` public class Title { public int id; public String tit; public Bitmap logo; public Bitmap getLogo() { return logo; } ... and other setter and getter } ``` and method returns Arraylist (in dba) with Title look like that: ``` public ArrayList<Title> returnTitle(){ Title t = new Title(1,"aaaaaaaaaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\favicon.ico")); Title t1 = new Title(2,"assdsdsdsdaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\icon.ico")); ArrayList<Title> art = new ArrayList<Title>(2); art.add(t); art.add(t1); return art; } ``` My List activity shows me only text. What I must change to see a image with text?
2011/11/25
[ "https://Stackoverflow.com/questions/8272897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1055201/" ]
By definition: http status code 503: Service Unavailable. The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state. As 500-599 present a server side error, happening all the time, on Web service or Web site. For 503, slowing down the frequency of the requests from your client program is a good way to go, and you might need to consider UI design as well if your client program has GUI>
I'm answering my own question. I won't accept it yet because this is only in concept stage. I think I'll create a common stack for all calls to services belonging to my provider. Every time a call is made, I'll set up a 'cool down' period using some form of thread or timer (I'm tempted to use this as an excuse to include [gabr](https://stackoverflow.com/users/4997/gabr)'s [OmniThread](http://otl.17slon.com/) library in my application.) So if two or more requests are submitted during the cool down period, I can chain them and show some fancy (\*) user interface to the user to avoid event breakage. If somebody has a better alternative, I'm all ears. *(\*): A dialog box with a progress bar, of course.*
8,272,897
I have a `ListActivity`, where I need to show a image and text in every row. The `event.xml` layout looks like this: ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_height="wrap_content" android:layout_width="30px" android:layout_marginTop="2px" android:layout_marginRight="2px" android:layout_marginLeft="2px" android:id="@+id/logoImage"> </ImageView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title" android:textSize="15px"></TextView> </LinearLayout> ``` The activity looks like this: ``` public class Activity extends ListActivity{ public void onCreate(Bundle icicle) { super.onCreate(icicle); dba=new DatabaseAdapter(this); dba.open(); View header = getLayoutInflater().inflate(R.layout.header, null); ListView lv = getListView(); lv.addHeaderView(header); fillOnStart(); } private void fillOnStart(){ ArrayList<Title> temp = dba.returnTitle(); // this works ArrAdapter notes = new ArrAdapter(this, temp); Toast.makeText(this, "Size: " +notes.getCount(), Toast.LENGTH_LONG).show(); //because this show good size setListAdapter(notes); } ``` and my adapter looks like this: ``` private class ArrAdapter extends BaseAdapter{ private Context mContext; private ArrayList<Title> lista; public ArrAdapter(Context c, ArrayList<Title> list){ mContext = c; this.lista =list; } public int getCount() { // TODO Auto-generated method stub return lista.size(); } public Object getItem(int position) { // TODO Auto-generated method stub return position; } public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // ViewHolder vh =null; Title title= lista.get(position); LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.event, parent, false); ImageView imlogo = (ImageView)v.findViewById(R.id.logoImage); TextView textTitle = (TextView)v.findViewById(R.id.title); imlogo.setImageResource(title.getLogo()); textTitle.setText(title.getTit()); return v; } } ``` class title looks like: ``` public class Title { public int id; public String tit; public Bitmap logo; public Bitmap getLogo() { return logo; } ... and other setter and getter } ``` and method returns Arraylist (in dba) with Title look like that: ``` public ArrayList<Title> returnTitle(){ Title t = new Title(1,"aaaaaaaaaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\favicon.ico")); Title t1 = new Title(2,"assdsdsdsdaa", BitmapFactory.decodeFile("C:\\Users\\hormon\\Desktop\\icon.ico")); ArrayList<Title> art = new ArrayList<Title>(2); art.add(t); art.add(t1); return art; } ``` My List activity shows me only text. What I must change to see a image with text?
2011/11/25
[ "https://Stackoverflow.com/questions/8272897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1055201/" ]
To handle a temorary error like 503, the message processing queue could use an incrementing delay time, a failed request will increase the waiting time (up to a defined maximum). If a request was successful, the delay is reset. So I would for example start with a 500 msec interval. Every time the request fails, the interval will be multiplied by two up to a maximum delay of 16 seconds. If a request returns without error, the interval is reset to its initial value of 500 msec.
I'm answering my own question. I won't accept it yet because this is only in concept stage. I think I'll create a common stack for all calls to services belonging to my provider. Every time a call is made, I'll set up a 'cool down' period using some form of thread or timer (I'm tempted to use this as an excuse to include [gabr](https://stackoverflow.com/users/4997/gabr)'s [OmniThread](http://otl.17slon.com/) library in my application.) So if two or more requests are submitted during the cool down period, I can chain them and show some fancy (\*) user interface to the user to avoid event breakage. If somebody has a better alternative, I'm all ears. *(\*): A dialog box with a progress bar, of course.*
25,975,746
I'm new to C++ and I am having problems setting up my class variables through the constructor. I have all of my .h and .cpp file setup in what I think is the correct way. But I keep getting errors on line 4 and 5. I am using Visual Studio 2013. The error says Vector3: 'class' type redefinition. And x, y,z is not a nonstatic data member or base class of class Vector3. Thanks for any advice. Vector3.h: ``` #ifndef VECTOR3_H #define VECTOR3_H #include <iostream> #include <array> class Vector3 { public: float x; float y; float z; Vector3(float _x, float _y, float _z); Vector3(const Vector3 &v); Vector3(Vector3 start, Vector3 end); Vector3 add(Vector3 v); Vector3 sub(Vector3 v); Vector3 scale(float scalar); float length(); void normalize(); float dot(Vector3 v3); float angleTo(Vector3 n); Vector3 cross(Vector3 v2); static bool isInFront(Vector3 front, Vector3 location, Vector3 target); static Vector3 findNormal(Vector3 points[]); }; #endif ``` Vector3.cpp: ``` #include "Vector3.h" class Vector3 { // error on this line Vector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) // error initializing variables { } Vector3(const Vector3 &v) { } Vector3(Vector3 start, Vector3 end) { } Vector3 add(Vector3 v) { } Vector3 sub(Vector3 v) { } Vector3 scale(float scalar) { } float length() { } void normalize() { } float dot(Vector3 v3) { } float angleTo(Vector3 n) { } Vector3 cross(Vector3 v2) { } static bool isInFront(Vector3 front, Vector3 location, Vector3 target) { } static Vector3 findNormal(Vector3 points[]) { } }; ```
2014/09/22
[ "https://Stackoverflow.com/questions/25975746", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2925538/" ]
You are re-defining the `class Vector3`. It should just be (the implementation); ``` Vector3::Vector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) // ^^^^ { } ``` And so on for all the member methods.
Change your .cpp body to this: Its a syntax error, you have to mention a class name in cpp before each funtion. ``` #include "Vector3.h" Vector3::Vector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) { } Vector3::Vector3(const Vector3 &v) { } Vector3::Vector3(Vector3 start, Vector3 end) { } Vector3 Vector3::add(Vector3 v) { } Vector3 Vector3::sub(Vector3 v) { } Vector3 Vector3::scale(float scalar) { } float Vector3::length() { } void Vector3::normalize() { } float Vector3::dot(Vector3 v3) { } float Vector3::angleTo(Vector3 n) { } Vector3 Vector3::cross(Vector3 v2) { } static bool Vector3::isInFront(Vector3 front, Vector3 location, Vector3 target) { } static Vector3 Vector3::findNormal(Vector3 points[]) { } ```
32,019
I understand that this circuit could be used as a treble control circuit with high frequency gain occuring when R3 is set so a=b (we'll call this k=0), and high frequency attenuation occuring when R3 is 22kOhms across a and b (k=1). So therefore, depending on R3's setting, this circuit is either a high pass (k=0) or low pass (k=1) filter. When comparing this circuit to high and low pass filters, I do not understand what is happening: C2 will always have a lower impedance for high frequencies and so surely adjusting R3 will only alter positive gain for high frequencies. I also understand that the capacitors act as an open circuit for low frequencies and so surely all low frequnencies would be attenuated. Can you help me understand this? Link to circuitlab.com schematic: <https://www.circuitlab.com/circuit/x66cq6/basic-frequency-control-circuit/> ![enter image description here](https://i.stack.imgur.com/aLYyb.jpg) By the way, I realise I have discussed this schematic in previous questions. Please note: I am asking something different to any of my previous questions. This is no duplicate question.
2012/05/16
[ "https://electronics.stackexchange.com/questions/32019", "https://electronics.stackexchange.com", "https://electronics.stackexchange.com/users/9374/" ]
The AC feedback via C2 is negative feedback - it will decrease the gain. Increasing the negative feedback with frequency will reduce the gain as frequency increases. C2 impedance decreases as frequency increases so feedback via C2 increases so gain decreases if all feedback is applied to inverting input. Final result will depend on where the feedback goes / how it is applied. Changing R3 split changes the overall "transfer function". It's not obvious that this is a formal design. Can you give a reference to where you got it from?
Rather than thinking of the capactior as such, think of it as simply a resistor who's value decreases linearly with the increasing frequency of the current flowing through it. An inductor can be considered in the same way except the frequency relationship is not inverse. (in this case rising 'reactance' with rising frequency) Now imagine an number identical circuits to the one you draw, e.g. three of them. Each drawn with a 'frequency dependent resistor' who's value is infinate at zero Hz but is replaced in each redrawn circuit to one that is a lot smaller than the other gain components at some frequency, e.g. 10kHz. You can now imagine what the gain does. 'Resistors' that reduce gain with increasing value will have the effect of a low pass filter. 'Resistors' that increase gain will have the effect of a high pass filter.
98,597
Is there any way I can verify the integrity of a remotely transferred file? I am currently transferring a large amount of files and folders from an ftp server to another remote server using wget, but I have no way of knowing if the files are corrupt. Is there any way I can verify the integrity of the transfer, by getting something like the MD5 hash of the remote files? Is there any other file transfer protocol that supports this?
2009/12/31
[ "https://serverfault.com/questions/98597", "https://serverfault.com", "https://serverfault.com/users/-1/" ]
Depending on the tool you use it's possible to automatically hash and verify the downloaded files, the only tool that can do this that comes to mind immediately though is the [DownThemAll!](https://addons.mozilla.org/en-US/firefox/addon/201 "DownThemAll!") addon for Firefox. What I normally use for situations like this a hash manifest file created by [md5deep](http://md5deep.sourceforge.net/ "md5deep") on Windows, you can use md5sum if you use Linux/UNIX or md5 on OS X. Using md5deep I CD to the folder containing the files to be transferred and run the command: ``` md5deep -l -r *>manifest.md5 ``` On the remote end after transferring the files and manifest you would run the command: ``` md5deep -l -r -x manifest.md5 * ``` And it will show a list of every file that DOES NOT match the hash value in the manifest.
While I really like the md5deep and rsync answers (and upvoted both), it sounds like you're facing a really hard group of people at the source server. An alternative that is really ugly but better than nothing is to cull the transfer log for the file sizes then compare them locally. ``` wget -nv -o log.txt ftp://ftp.myserver.com/welcome.msg ``` ...created a logfile line that looks like this: ``` 2010-01-01 09:47:17 URL: ftp://ftp.myserver.com/welcome.msg [470] -> "welcome.msg" [1] ``` So by using a little script-fu with some awk or whatnot, you can pull out the filename and filesize, then at least compare that they match. I reiterate that this isn't pretty and should be your last-ditch solution...but it works.
98,597
Is there any way I can verify the integrity of a remotely transferred file? I am currently transferring a large amount of files and folders from an ftp server to another remote server using wget, but I have no way of knowing if the files are corrupt. Is there any way I can verify the integrity of the transfer, by getting something like the MD5 hash of the remote files? Is there any other file transfer protocol that supports this?
2009/12/31
[ "https://serverfault.com/questions/98597", "https://serverfault.com", "https://serverfault.com/users/-1/" ]
Depending on the tool you use it's possible to automatically hash and verify the downloaded files, the only tool that can do this that comes to mind immediately though is the [DownThemAll!](https://addons.mozilla.org/en-US/firefox/addon/201 "DownThemAll!") addon for Firefox. What I normally use for situations like this a hash manifest file created by [md5deep](http://md5deep.sourceforge.net/ "md5deep") on Windows, you can use md5sum if you use Linux/UNIX or md5 on OS X. Using md5deep I CD to the folder containing the files to be transferred and run the command: ``` md5deep -l -r *>manifest.md5 ``` On the remote end after transferring the files and manifest you would run the command: ``` md5deep -l -r -x manifest.md5 * ``` And it will show a list of every file that DOES NOT match the hash value in the manifest.
That's a long shot, but if the server supports [php](https://php.net), you can exploit that. Save the following as a `php` file (say, `check.php`), in the same folder as your `name_of_file.txt` file: ``` <? php echo md5_file('name_of_file.txt'); php> ``` Then, visit the page `check.php`, and you should get the md5 hash of your file. Related questions: * <https://stackoverflow.com/q/29909233/2657549> * <https://stackoverflow.com/q/30626006/2657549> * <https://stackoverflow.com/q/30056566/2657549>
98,597
Is there any way I can verify the integrity of a remotely transferred file? I am currently transferring a large amount of files and folders from an ftp server to another remote server using wget, but I have no way of knowing if the files are corrupt. Is there any way I can verify the integrity of the transfer, by getting something like the MD5 hash of the remote files? Is there any other file transfer protocol that supports this?
2009/12/31
[ "https://serverfault.com/questions/98597", "https://serverfault.com", "https://serverfault.com/users/-1/" ]
`rsync` is almost always the best answer for file transfers. It's best known for its differential optimization transfers (great when you already have a similar file or directory) but it profusely checksums every step of the transmissions.
While I really like the md5deep and rsync answers (and upvoted both), it sounds like you're facing a really hard group of people at the source server. An alternative that is really ugly but better than nothing is to cull the transfer log for the file sizes then compare them locally. ``` wget -nv -o log.txt ftp://ftp.myserver.com/welcome.msg ``` ...created a logfile line that looks like this: ``` 2010-01-01 09:47:17 URL: ftp://ftp.myserver.com/welcome.msg [470] -> "welcome.msg" [1] ``` So by using a little script-fu with some awk or whatnot, you can pull out the filename and filesize, then at least compare that they match. I reiterate that this isn't pretty and should be your last-ditch solution...but it works.
98,597
Is there any way I can verify the integrity of a remotely transferred file? I am currently transferring a large amount of files and folders from an ftp server to another remote server using wget, but I have no way of knowing if the files are corrupt. Is there any way I can verify the integrity of the transfer, by getting something like the MD5 hash of the remote files? Is there any other file transfer protocol that supports this?
2009/12/31
[ "https://serverfault.com/questions/98597", "https://serverfault.com", "https://serverfault.com/users/-1/" ]
`rsync` is almost always the best answer for file transfers. It's best known for its differential optimization transfers (great when you already have a similar file or directory) but it profusely checksums every step of the transmissions.
That's a long shot, but if the server supports [php](https://php.net), you can exploit that. Save the following as a `php` file (say, `check.php`), in the same folder as your `name_of_file.txt` file: ``` <? php echo md5_file('name_of_file.txt'); php> ``` Then, visit the page `check.php`, and you should get the md5 hash of your file. Related questions: * <https://stackoverflow.com/q/29909233/2657549> * <https://stackoverflow.com/q/30626006/2657549> * <https://stackoverflow.com/q/30056566/2657549>
98,597
Is there any way I can verify the integrity of a remotely transferred file? I am currently transferring a large amount of files and folders from an ftp server to another remote server using wget, but I have no way of knowing if the files are corrupt. Is there any way I can verify the integrity of the transfer, by getting something like the MD5 hash of the remote files? Is there any other file transfer protocol that supports this?
2009/12/31
[ "https://serverfault.com/questions/98597", "https://serverfault.com", "https://serverfault.com/users/-1/" ]
While I really like the md5deep and rsync answers (and upvoted both), it sounds like you're facing a really hard group of people at the source server. An alternative that is really ugly but better than nothing is to cull the transfer log for the file sizes then compare them locally. ``` wget -nv -o log.txt ftp://ftp.myserver.com/welcome.msg ``` ...created a logfile line that looks like this: ``` 2010-01-01 09:47:17 URL: ftp://ftp.myserver.com/welcome.msg [470] -> "welcome.msg" [1] ``` So by using a little script-fu with some awk or whatnot, you can pull out the filename and filesize, then at least compare that they match. I reiterate that this isn't pretty and should be your last-ditch solution...but it works.
That's a long shot, but if the server supports [php](https://php.net), you can exploit that. Save the following as a `php` file (say, `check.php`), in the same folder as your `name_of_file.txt` file: ``` <? php echo md5_file('name_of_file.txt'); php> ``` Then, visit the page `check.php`, and you should get the md5 hash of your file. Related questions: * <https://stackoverflow.com/q/29909233/2657549> * <https://stackoverflow.com/q/30626006/2657549> * <https://stackoverflow.com/q/30056566/2657549>
66,863,639
Suppose I have a list of string: ``` distance <- c("CHI #12 DEBRINCAT(1), Snap, Off. Zone, 18 ft.Assists: #88 KANE(2); #56 GUSTAFSSON(1)", "TOR ONGOAL - #44 RIELLY, Backhand, Off. Zone, 77 ft.") ``` Now I hope to get a string vector that contains only the parts that contains the distance, that is, substring = c ("18 ft", "77 ft"). Is there a convenient way in R to do this?
2021/03/30
[ "https://Stackoverflow.com/questions/66863639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14503956/" ]
Using `str_extract` to match one or more digits followed by zero or more spaces (`\\s*`) and the substring 'ft' ``` library(stringr) str_extract(distance, "\\d+\\s*ft") #[1] "18 ft" "77 ft" ```
Alternatives: ```r regmatches(distance, gregexpr("\\b[0-9]+\\s*ft", distance, perl = TRUE)) # [[1]] # [1] "18 ft" # [[2]] # [1] "77 ft" strcapture("\\b([0-9]+\\s*ft)", distance, list(dist = "")) # dist # 1 18 ft # 2 77 ft ``` Though they're all just doing the same thing with slightly different interfaces.
66,863,639
Suppose I have a list of string: ``` distance <- c("CHI #12 DEBRINCAT(1), Snap, Off. Zone, 18 ft.Assists: #88 KANE(2); #56 GUSTAFSSON(1)", "TOR ONGOAL - #44 RIELLY, Backhand, Off. Zone, 77 ft.") ``` Now I hope to get a string vector that contains only the parts that contains the distance, that is, substring = c ("18 ft", "77 ft"). Is there a convenient way in R to do this?
2021/03/30
[ "https://Stackoverflow.com/questions/66863639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14503956/" ]
Using `str_extract` to match one or more digits followed by zero or more spaces (`\\s*`) and the substring 'ft' ``` library(stringr) str_extract(distance, "\\d+\\s*ft") #[1] "18 ft" "77 ft" ```
Try `gsub` ``` > gsub(".*?(\\d+\\s+ft).*", "\\1", distance) [1] "18 ft" "77 ft" ```
66,863,639
Suppose I have a list of string: ``` distance <- c("CHI #12 DEBRINCAT(1), Snap, Off. Zone, 18 ft.Assists: #88 KANE(2); #56 GUSTAFSSON(1)", "TOR ONGOAL - #44 RIELLY, Backhand, Off. Zone, 77 ft.") ``` Now I hope to get a string vector that contains only the parts that contains the distance, that is, substring = c ("18 ft", "77 ft"). Is there a convenient way in R to do this?
2021/03/30
[ "https://Stackoverflow.com/questions/66863639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14503956/" ]
Alternatives: ```r regmatches(distance, gregexpr("\\b[0-9]+\\s*ft", distance, perl = TRUE)) # [[1]] # [1] "18 ft" # [[2]] # [1] "77 ft" strcapture("\\b([0-9]+\\s*ft)", distance, list(dist = "")) # dist # 1 18 ft # 2 77 ft ``` Though they're all just doing the same thing with slightly different interfaces.
Try `gsub` ``` > gsub(".*?(\\d+\\s+ft).*", "\\1", distance) [1] "18 ft" "77 ft" ```
1,250,253
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit. I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like: ``` for( int i = 0; i < imgLength; i++) { if( myBitArray[i] == 1 ) { // ... do stuff ... } } ``` Performance is usable, but not amazing. I run the program through gprof and find out there is significant time and millions of calls to `std::vector` methods like iterator and begin. Here's the top-sampled functions: ``` Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 37.91 0.80 0.80 2 0.40 1.01 findPattern(bit_array_c*, bool*, int, int, int) 12.32 1.06 0.26 98375762 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char const* const&) 11.85 1.31 0.25 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator+(int const&) const 11.37 1.55 0.24 49187881 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::begin() const 9.24 1.75 0.20 48183659 0.00 0.00 bit_array_c::operator[](unsigned int) const 8.06 1.92 0.17 48183659 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::operator[](unsigned int) const 5.21 2.02 0.11 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.95 2.04 0.02 bit_array_c::operator()(unsigned int) 0.47 2.06 0.01 6025316 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char* const&) 0.47 2.06 0.01 3012657 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.47 2.08 0.01 1004222 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::end() const ... remainder omitted ... ``` I'm not really familiar with C++'s STL, but can anyone shed light on why, for instance, std::vector::begin() is being called a few million times? And, of course, whether there's something I can be doing to speed it up? **Edit:** I just gave up and optimized the search function (the loop) instead.
2009/08/09
[ "https://Stackoverflow.com/questions/1250253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/140827/" ]
Without seeing your code it's hard to make specific comments about how to speed up what you are doing. However, `vector::begin()` is used to return an iterator to the first element in a vector - it's a standard routine when iterating across a vector. I'd actually recommend using a more modern profiler such as [OProfile](http://oprofile.sourceforge.net/docs/), this will give you much finer-grained information on where your program is spending it's time - down to the actual C++ line, or even the individual asm instruction, depending on how you run it. As an aside - why did you choose to use [bitarray.cpp](http://michael.dipperstein.com/bitlibs/) instead of a vanilla `std::vector<bool>`? I've not used it myself, but a quick scan of the above link suggests that `bitarray.cpp` supports additional functionality over `std::vector<bool>`, which if you arn't making use of may well add overhead compared to the STL vector class...
You could improve performance by using a pointer/iterator (I'm not sure what exactly bitarray.cpp does for you), like this: ``` for (bool *ptr = myBitArray, int i = 0; i != imgLength; ++i, ++ptr) { if (*myBitArray == 1) { //handle } } ``` I only use int i here because I'm not sure if your bit array would be null terminated, in which case your condition could simply be ``` *myBitArray != '\0'; ``` Or you could hack out a better end condition. Using an std::iterator would be best, but I doubt your bitarray would support it. Edit: Normally this would be a micro-optimization, but if you loop over enough things, it will probably improve performance slightly.
1,250,253
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit. I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like: ``` for( int i = 0; i < imgLength; i++) { if( myBitArray[i] == 1 ) { // ... do stuff ... } } ``` Performance is usable, but not amazing. I run the program through gprof and find out there is significant time and millions of calls to `std::vector` methods like iterator and begin. Here's the top-sampled functions: ``` Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 37.91 0.80 0.80 2 0.40 1.01 findPattern(bit_array_c*, bool*, int, int, int) 12.32 1.06 0.26 98375762 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char const* const&) 11.85 1.31 0.25 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator+(int const&) const 11.37 1.55 0.24 49187881 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::begin() const 9.24 1.75 0.20 48183659 0.00 0.00 bit_array_c::operator[](unsigned int) const 8.06 1.92 0.17 48183659 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::operator[](unsigned int) const 5.21 2.02 0.11 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.95 2.04 0.02 bit_array_c::operator()(unsigned int) 0.47 2.06 0.01 6025316 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char* const&) 0.47 2.06 0.01 3012657 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.47 2.08 0.01 1004222 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::end() const ... remainder omitted ... ``` I'm not really familiar with C++'s STL, but can anyone shed light on why, for instance, std::vector::begin() is being called a few million times? And, of course, whether there's something I can be doing to speed it up? **Edit:** I just gave up and optimized the search function (the loop) instead.
2009/08/09
[ "https://Stackoverflow.com/questions/1250253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/140827/" ]
Without seeing your code it's hard to make specific comments about how to speed up what you are doing. However, `vector::begin()` is used to return an iterator to the first element in a vector - it's a standard routine when iterating across a vector. I'd actually recommend using a more modern profiler such as [OProfile](http://oprofile.sourceforge.net/docs/), this will give you much finer-grained information on where your program is spending it's time - down to the actual C++ line, or even the individual asm instruction, depending on how you run it. As an aside - why did you choose to use [bitarray.cpp](http://michael.dipperstein.com/bitlibs/) instead of a vanilla `std::vector<bool>`? I've not used it myself, but a quick scan of the above link suggests that `bitarray.cpp` supports additional functionality over `std::vector<bool>`, which if you arn't making use of may well add overhead compared to the STL vector class...
If performance matters enough that you have to worry about accessing individual bits, then you should probably parallelize your code. Since you describe this as image processing, odds are that the state of bit i won't affect how you handle bits i+1 through i+6, so you can probably rewrite your code to operate on bytes and words at a time. Just being able to increment your counter 8 to 64 times less often should provide a measurable performance increase, and will also make it easier for the compiler to optimize your code.
1,250,253
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit. I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like: ``` for( int i = 0; i < imgLength; i++) { if( myBitArray[i] == 1 ) { // ... do stuff ... } } ``` Performance is usable, but not amazing. I run the program through gprof and find out there is significant time and millions of calls to `std::vector` methods like iterator and begin. Here's the top-sampled functions: ``` Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 37.91 0.80 0.80 2 0.40 1.01 findPattern(bit_array_c*, bool*, int, int, int) 12.32 1.06 0.26 98375762 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char const* const&) 11.85 1.31 0.25 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator+(int const&) const 11.37 1.55 0.24 49187881 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::begin() const 9.24 1.75 0.20 48183659 0.00 0.00 bit_array_c::operator[](unsigned int) const 8.06 1.92 0.17 48183659 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::operator[](unsigned int) const 5.21 2.02 0.11 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.95 2.04 0.02 bit_array_c::operator()(unsigned int) 0.47 2.06 0.01 6025316 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char* const&) 0.47 2.06 0.01 3012657 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.47 2.08 0.01 1004222 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::end() const ... remainder omitted ... ``` I'm not really familiar with C++'s STL, but can anyone shed light on why, for instance, std::vector::begin() is being called a few million times? And, of course, whether there's something I can be doing to speed it up? **Edit:** I just gave up and optimized the search function (the loop) instead.
2009/08/09
[ "https://Stackoverflow.com/questions/1250253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/140827/" ]
The fact that you see a lot of inline functions in your profile output implies that they aren't being inlined -- that is, you aren't compiling with optimization turned on. So the simplest thing you could do to optimize your code would be to use -O2 or -O3. Profiling unoptimized code is rarely worthwhile, since the execution profile of optimized and unoptimized code will likely be completely different.33
Without seeing your code it's hard to make specific comments about how to speed up what you are doing. However, `vector::begin()` is used to return an iterator to the first element in a vector - it's a standard routine when iterating across a vector. I'd actually recommend using a more modern profiler such as [OProfile](http://oprofile.sourceforge.net/docs/), this will give you much finer-grained information on where your program is spending it's time - down to the actual C++ line, or even the individual asm instruction, depending on how you run it. As an aside - why did you choose to use [bitarray.cpp](http://michael.dipperstein.com/bitlibs/) instead of a vanilla `std::vector<bool>`? I've not used it myself, but a quick scan of the above link suggests that `bitarray.cpp` supports additional functionality over `std::vector<bool>`, which if you arn't making use of may well add overhead compared to the STL vector class...
1,250,253
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit. I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like: ``` for( int i = 0; i < imgLength; i++) { if( myBitArray[i] == 1 ) { // ... do stuff ... } } ``` Performance is usable, but not amazing. I run the program through gprof and find out there is significant time and millions of calls to `std::vector` methods like iterator and begin. Here's the top-sampled functions: ``` Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 37.91 0.80 0.80 2 0.40 1.01 findPattern(bit_array_c*, bool*, int, int, int) 12.32 1.06 0.26 98375762 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char const* const&) 11.85 1.31 0.25 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator+(int const&) const 11.37 1.55 0.24 49187881 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::begin() const 9.24 1.75 0.20 48183659 0.00 0.00 bit_array_c::operator[](unsigned int) const 8.06 1.92 0.17 48183659 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::operator[](unsigned int) const 5.21 2.02 0.11 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.95 2.04 0.02 bit_array_c::operator()(unsigned int) 0.47 2.06 0.01 6025316 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char* const&) 0.47 2.06 0.01 3012657 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.47 2.08 0.01 1004222 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::end() const ... remainder omitted ... ``` I'm not really familiar with C++'s STL, but can anyone shed light on why, for instance, std::vector::begin() is being called a few million times? And, of course, whether there's something I can be doing to speed it up? **Edit:** I just gave up and optimized the search function (the loop) instead.
2009/08/09
[ "https://Stackoverflow.com/questions/1250253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/140827/" ]
a quick peak into the code for bitarray.cpp shows: ``` bool bit_array_c::operator[](const unsigned int bit) const { return((m_Array[BIT_CHAR(bit)] & BIT_IN_CHAR(bit)) != 0); } ``` m\_Array is of type std::vector the [] operator on STL vectors is of constant complexity but its likely implemented as a call to vector::begin to get the base address of the array and then it calculates an offset to get to the value you want. since bitarray.cpp makes a call to the [] operator on EVERY BIT ACCESS you are getting a lot of calls. given your use case i would create a custom implementation of the functionality contained in bitarray.cpp and tune it for your sequential, bit by bit, access pattern. * Don't use unsigned char's, use 32 or 64 bit values to reduce the number of memory accesses needed. * I would use a normal array, not a vector to avoid the look up overhead * Create a sequential access function, nextbit() that doesn't do all the look ups. Store a pointer to the current "value" all you need to do in increment it on the 32/64 bit boundary, all accesses between boundaries are a simple mask/shift operations and should be very fast.
Without seeing your code it's hard to make specific comments about how to speed up what you are doing. However, `vector::begin()` is used to return an iterator to the first element in a vector - it's a standard routine when iterating across a vector. I'd actually recommend using a more modern profiler such as [OProfile](http://oprofile.sourceforge.net/docs/), this will give you much finer-grained information on where your program is spending it's time - down to the actual C++ line, or even the individual asm instruction, depending on how you run it. As an aside - why did you choose to use [bitarray.cpp](http://michael.dipperstein.com/bitlibs/) instead of a vanilla `std::vector<bool>`? I've not used it myself, but a quick scan of the above link suggests that `bitarray.cpp` supports additional functionality over `std::vector<bool>`, which if you arn't making use of may well add overhead compared to the STL vector class...
1,250,253
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit. I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like: ``` for( int i = 0; i < imgLength; i++) { if( myBitArray[i] == 1 ) { // ... do stuff ... } } ``` Performance is usable, but not amazing. I run the program through gprof and find out there is significant time and millions of calls to `std::vector` methods like iterator and begin. Here's the top-sampled functions: ``` Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 37.91 0.80 0.80 2 0.40 1.01 findPattern(bit_array_c*, bool*, int, int, int) 12.32 1.06 0.26 98375762 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char const* const&) 11.85 1.31 0.25 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator+(int const&) const 11.37 1.55 0.24 49187881 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::begin() const 9.24 1.75 0.20 48183659 0.00 0.00 bit_array_c::operator[](unsigned int) const 8.06 1.92 0.17 48183659 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::operator[](unsigned int) const 5.21 2.02 0.11 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.95 2.04 0.02 bit_array_c::operator()(unsigned int) 0.47 2.06 0.01 6025316 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char* const&) 0.47 2.06 0.01 3012657 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.47 2.08 0.01 1004222 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::end() const ... remainder omitted ... ``` I'm not really familiar with C++'s STL, but can anyone shed light on why, for instance, std::vector::begin() is being called a few million times? And, of course, whether there's something I can be doing to speed it up? **Edit:** I just gave up and optimized the search function (the loop) instead.
2009/08/09
[ "https://Stackoverflow.com/questions/1250253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/140827/" ]
The fact that you see a lot of inline functions in your profile output implies that they aren't being inlined -- that is, you aren't compiling with optimization turned on. So the simplest thing you could do to optimize your code would be to use -O2 or -O3. Profiling unoptimized code is rarely worthwhile, since the execution profile of optimized and unoptimized code will likely be completely different.33
You could improve performance by using a pointer/iterator (I'm not sure what exactly bitarray.cpp does for you), like this: ``` for (bool *ptr = myBitArray, int i = 0; i != imgLength; ++i, ++ptr) { if (*myBitArray == 1) { //handle } } ``` I only use int i here because I'm not sure if your bit array would be null terminated, in which case your condition could simply be ``` *myBitArray != '\0'; ``` Or you could hack out a better end condition. Using an std::iterator would be best, but I doubt your bitarray would support it. Edit: Normally this would be a micro-optimization, but if you loop over enough things, it will probably improve performance slightly.
1,250,253
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit. I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like: ``` for( int i = 0; i < imgLength; i++) { if( myBitArray[i] == 1 ) { // ... do stuff ... } } ``` Performance is usable, but not amazing. I run the program through gprof and find out there is significant time and millions of calls to `std::vector` methods like iterator and begin. Here's the top-sampled functions: ``` Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 37.91 0.80 0.80 2 0.40 1.01 findPattern(bit_array_c*, bool*, int, int, int) 12.32 1.06 0.26 98375762 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char const* const&) 11.85 1.31 0.25 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator+(int const&) const 11.37 1.55 0.24 49187881 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::begin() const 9.24 1.75 0.20 48183659 0.00 0.00 bit_array_c::operator[](unsigned int) const 8.06 1.92 0.17 48183659 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::operator[](unsigned int) const 5.21 2.02 0.11 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.95 2.04 0.02 bit_array_c::operator()(unsigned int) 0.47 2.06 0.01 6025316 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char* const&) 0.47 2.06 0.01 3012657 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.47 2.08 0.01 1004222 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::end() const ... remainder omitted ... ``` I'm not really familiar with C++'s STL, but can anyone shed light on why, for instance, std::vector::begin() is being called a few million times? And, of course, whether there's something I can be doing to speed it up? **Edit:** I just gave up and optimized the search function (the loop) instead.
2009/08/09
[ "https://Stackoverflow.com/questions/1250253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/140827/" ]
a quick peak into the code for bitarray.cpp shows: ``` bool bit_array_c::operator[](const unsigned int bit) const { return((m_Array[BIT_CHAR(bit)] & BIT_IN_CHAR(bit)) != 0); } ``` m\_Array is of type std::vector the [] operator on STL vectors is of constant complexity but its likely implemented as a call to vector::begin to get the base address of the array and then it calculates an offset to get to the value you want. since bitarray.cpp makes a call to the [] operator on EVERY BIT ACCESS you are getting a lot of calls. given your use case i would create a custom implementation of the functionality contained in bitarray.cpp and tune it for your sequential, bit by bit, access pattern. * Don't use unsigned char's, use 32 or 64 bit values to reduce the number of memory accesses needed. * I would use a normal array, not a vector to avoid the look up overhead * Create a sequential access function, nextbit() that doesn't do all the look ups. Store a pointer to the current "value" all you need to do in increment it on the 32/64 bit boundary, all accesses between boundaries are a simple mask/shift operations and should be very fast.
You could improve performance by using a pointer/iterator (I'm not sure what exactly bitarray.cpp does for you), like this: ``` for (bool *ptr = myBitArray, int i = 0; i != imgLength; ++i, ++ptr) { if (*myBitArray == 1) { //handle } } ``` I only use int i here because I'm not sure if your bit array would be null terminated, in which case your condition could simply be ``` *myBitArray != '\0'; ``` Or you could hack out a better end condition. Using an std::iterator would be best, but I doubt your bitarray would support it. Edit: Normally this would be a micro-optimization, but if you loop over enough things, it will probably improve performance slightly.
1,250,253
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit. I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like: ``` for( int i = 0; i < imgLength; i++) { if( myBitArray[i] == 1 ) { // ... do stuff ... } } ``` Performance is usable, but not amazing. I run the program through gprof and find out there is significant time and millions of calls to `std::vector` methods like iterator and begin. Here's the top-sampled functions: ``` Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 37.91 0.80 0.80 2 0.40 1.01 findPattern(bit_array_c*, bool*, int, int, int) 12.32 1.06 0.26 98375762 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char const* const&) 11.85 1.31 0.25 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator+(int const&) const 11.37 1.55 0.24 49187881 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::begin() const 9.24 1.75 0.20 48183659 0.00 0.00 bit_array_c::operator[](unsigned int) const 8.06 1.92 0.17 48183659 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::operator[](unsigned int) const 5.21 2.02 0.11 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.95 2.04 0.02 bit_array_c::operator()(unsigned int) 0.47 2.06 0.01 6025316 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char* const&) 0.47 2.06 0.01 3012657 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.47 2.08 0.01 1004222 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::end() const ... remainder omitted ... ``` I'm not really familiar with C++'s STL, but can anyone shed light on why, for instance, std::vector::begin() is being called a few million times? And, of course, whether there's something I can be doing to speed it up? **Edit:** I just gave up and optimized the search function (the loop) instead.
2009/08/09
[ "https://Stackoverflow.com/questions/1250253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/140827/" ]
The fact that you see a lot of inline functions in your profile output implies that they aren't being inlined -- that is, you aren't compiling with optimization turned on. So the simplest thing you could do to optimize your code would be to use -O2 or -O3. Profiling unoptimized code is rarely worthwhile, since the execution profile of optimized and unoptimized code will likely be completely different.33
If performance matters enough that you have to worry about accessing individual bits, then you should probably parallelize your code. Since you describe this as image processing, odds are that the state of bit i won't affect how you handle bits i+1 through i+6, so you can probably rewrite your code to operate on bytes and words at a time. Just being able to increment your counter 8 to 64 times less often should provide a measurable performance increase, and will also make it easier for the compiler to optimize your code.
1,250,253
I'm using Dipperstein's bitarray.cpp class to work on bi-level (black and white) images where the image data is natively stored as simply as one pixel one bit. I need to iterate through each and every bit, on the order of 4--9 megapixels per image, over hundreds of images, using a for loop, something like: ``` for( int i = 0; i < imgLength; i++) { if( myBitArray[i] == 1 ) { // ... do stuff ... } } ``` Performance is usable, but not amazing. I run the program through gprof and find out there is significant time and millions of calls to `std::vector` methods like iterator and begin. Here's the top-sampled functions: ``` Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 37.91 0.80 0.80 2 0.40 1.01 findPattern(bit_array_c*, bool*, int, int, int) 12.32 1.06 0.26 98375762 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char const* const&) 11.85 1.31 0.25 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator+(int const&) const 11.37 1.55 0.24 49187881 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::begin() const 9.24 1.75 0.20 48183659 0.00 0.00 bit_array_c::operator[](unsigned int) const 8.06 1.92 0.17 48183659 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::operator[](unsigned int) const 5.21 2.02 0.11 48183659 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.95 2.04 0.02 bit_array_c::operator()(unsigned int) 0.47 2.06 0.01 6025316 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::__normal_iterator(unsigned char* const&) 0.47 2.06 0.01 3012657 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::operator*() const 0.47 2.08 0.01 1004222 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::end() const ... remainder omitted ... ``` I'm not really familiar with C++'s STL, but can anyone shed light on why, for instance, std::vector::begin() is being called a few million times? And, of course, whether there's something I can be doing to speed it up? **Edit:** I just gave up and optimized the search function (the loop) instead.
2009/08/09
[ "https://Stackoverflow.com/questions/1250253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/140827/" ]
a quick peak into the code for bitarray.cpp shows: ``` bool bit_array_c::operator[](const unsigned int bit) const { return((m_Array[BIT_CHAR(bit)] & BIT_IN_CHAR(bit)) != 0); } ``` m\_Array is of type std::vector the [] operator on STL vectors is of constant complexity but its likely implemented as a call to vector::begin to get the base address of the array and then it calculates an offset to get to the value you want. since bitarray.cpp makes a call to the [] operator on EVERY BIT ACCESS you are getting a lot of calls. given your use case i would create a custom implementation of the functionality contained in bitarray.cpp and tune it for your sequential, bit by bit, access pattern. * Don't use unsigned char's, use 32 or 64 bit values to reduce the number of memory accesses needed. * I would use a normal array, not a vector to avoid the look up overhead * Create a sequential access function, nextbit() that doesn't do all the look ups. Store a pointer to the current "value" all you need to do in increment it on the 32/64 bit boundary, all accesses between boundaries are a simple mask/shift operations and should be very fast.
If performance matters enough that you have to worry about accessing individual bits, then you should probably parallelize your code. Since you describe this as image processing, odds are that the state of bit i won't affect how you handle bits i+1 through i+6, so you can probably rewrite your code to operate on bytes and words at a time. Just being able to increment your counter 8 to 64 times less often should provide a measurable performance increase, and will also make it easier for the compiler to optimize your code.
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
**Academics that make research using computers, not research about computers.** They: - are writing software that can consume unlimited quantities of CPU time, memory and disc space so they care (or at least try to care) of performance, *either* by using stuff like `-O3`, `time`, profilers, memcheck, and spend hours more or less randomly changing the code to gather some speedup *or* mindlessly applying some mythical tricks to their scrips. - use real numbers and know that it is tricky enough so a separate science named "numerics" can exist. - often use some very specific programming languages/libraries/programs and are very fanatic about it; flame wars are common, mostly about performance. - call their programs "codes" to highlight that they have so obfuscated user interface so only their creators know how to use it. - usually work on Linux or at least use PuTTY to ssh to some Linux workstation/cluster.
Count me down as the 'old-school' guy. I never did LISP well, though. Emacs? Nah, `vi` and `set -o vi` in my shell for me thank you.
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
I'd consider myself part of the **Real-Time Systems** group. There are some 'Old School' characteristics but with less focus on CS, more on hardware. The archetype: * Has expert knowledge of 'C' + Has an original copy of K&R + Writes in other languages as if they were just an alternate syntax for 'C' * Can predict the assembler output from their code. * Can read a circuit diagram * Doesn't know how to write code without doing 'premature optimization'. * Is quite comfortable with the command line.
I represent the lonely contingent of Delphi Devs under 30. Our caucus is small, but our hearts are big.
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
I'd consider myself part of the **Real-Time Systems** group. There are some 'Old School' characteristics but with less focus on CS, more on hardware. The archetype: * Has expert knowledge of 'C' + Has an original copy of K&R + Writes in other languages as if they were just an alternate syntax for 'C' * Can predict the assembler output from their code. * Can read a circuit diagram * Doesn't know how to write code without doing 'premature optimization'. * Is quite comfortable with the command line.
I guess that there exists several cultures which somehow live alongside rather then fight and are somehow transcendent: * **Hacker/Open Source culture**: sharing code, uses real name or not. Concentrated probably on small tools that solve one problem. Allows in-program hacks. Languages: *C*, *Lisp*, *C++*, *Python*. Probably overlaps with yours **Old-school CS people**. * **Academia**: concentration on algorithms and doing things in the right way. The real name is must (it appears on paper anyway). Languages: *Java*, *Haskell*, (*F#*?) * **Corportate**: concentration on solutions (probably of everything). If open source that [giving the name is not necessary](http://en.wikipedia.org/wiki/Why_the_lucky_stiff). Languages: *Java*, *C#*, *VB.net*, *Ruby*. * "**High School**": it goods if it work but it doesn't have to. Concentration on names like "SuperProgram 1.0 for Windows XP". (sorry - I haven't found good name but I mean the programmers who started mastering CS and are not good at it - at least yet). Languages: *PHP*, *VB*, *Ruby* * **New School Web Developers**: As above. Please note that: * it is possible to mix the cultures in organizations and in single person. In fact it often does. * The languages are **EXAMPLES** and it is for example quite large group of "hackers" working on C#. It is more of game of associations the real study so please don't be offended (yes - I do know that there are great programms written in PHP with good engeneering practice etc. but it tend to be first language for many people who don't know what for example XSS is) * I didn't want to offend anyone by name High School. I meant that it is often first step into programming via this culture (and hopefully not last) * ***Edit:*** **Academia** does not mean that person is in academia as well as being in academia does not mean that someone belongs to **academia** (despite being briliant scientist/researcher etc.). It denotes that he preferes the tools which gives clear, obviously correct solution even if it lacks performance/takes longer time/... Similary **Corporate** culture is not equivlent to corporations. I think I'm currently mostly Open Source with slight influence of Academia (passive).
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
I'd consider myself part of the **Real-Time Systems** group. There are some 'Old School' characteristics but with less focus on CS, more on hardware. The archetype: * Has expert knowledge of 'C' + Has an original copy of K&R + Writes in other languages as if they were just an alternate syntax for 'C' * Can predict the assembler output from their code. * Can read a circuit diagram * Doesn't know how to write code without doing 'premature optimization'. * Is quite comfortable with the command line.
Count me down as the 'old-school' guy. I never did LISP well, though. Emacs? Nah, `vi` and `set -o vi` in my shell for me thank you.
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
I represent the lonely contingent of Delphi Devs under 30. Our caucus is small, but our hearts are big.
I'm kind of in the Alt.NET/old-school CS camp. I work with Microsoft tech (C#, etc.), but I'm aware that there's a whole world around me, other languages, algorithms, frameworks, "stuff under the hood", etc. Not perfect, obviously, but it's a work in progress.
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
**Academics that make research using computers, not research about computers.** They: - are writing software that can consume unlimited quantities of CPU time, memory and disc space so they care (or at least try to care) of performance, *either* by using stuff like `-O3`, `time`, profilers, memcheck, and spend hours more or less randomly changing the code to gather some speedup *or* mindlessly applying some mythical tricks to their scrips. - use real numbers and know that it is tricky enough so a separate science named "numerics" can exist. - often use some very specific programming languages/libraries/programs and are very fanatic about it; flame wars are common, mostly about performance. - call their programs "codes" to highlight that they have so obfuscated user interface so only their creators know how to use it. - usually work on Linux or at least use PuTTY to ssh to some Linux workstation/cluster.
I'm probably a combination of **Old-school CS people** and **New-school web developers**: I learned programming by writing websites with PHP, Javascript and SQL, and am now attending university where everything is done in command-prompts and Emacs under UNIX.
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
I'd consider myself part of the **Real-Time Systems** group. There are some 'Old School' characteristics but with less focus on CS, more on hardware. The archetype: * Has expert knowledge of 'C' + Has an original copy of K&R + Writes in other languages as if they were just an alternate syntax for 'C' * Can predict the assembler output from their code. * Can read a circuit diagram * Doesn't know how to write code without doing 'premature optimization'. * Is quite comfortable with the command line.
I don't entirely agree with this statement about MS subculture: "Don't see what the fuss with open-source and such is all about - besides, who needs to know another language? Generally, I've found such places to be 9-5 and quite corporate (driven by business managers, not software people). The anti-thesis of the hacker culture.". I've worked at two .Net shops by now and the environment was actually very hacker-like. We've employed many open-source projects in our work. In my option, it all depends on the kind of people that one works with. If they're true developers, they will constantly look for ways to improve, branch out. What technologies they use is irrelevant. Don't forget about the Agile Methodology subculture that incorporates developers from different backgrounds.
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
I guess that there exists several cultures which somehow live alongside rather then fight and are somehow transcendent: * **Hacker/Open Source culture**: sharing code, uses real name or not. Concentrated probably on small tools that solve one problem. Allows in-program hacks. Languages: *C*, *Lisp*, *C++*, *Python*. Probably overlaps with yours **Old-school CS people**. * **Academia**: concentration on algorithms and doing things in the right way. The real name is must (it appears on paper anyway). Languages: *Java*, *Haskell*, (*F#*?) * **Corportate**: concentration on solutions (probably of everything). If open source that [giving the name is not necessary](http://en.wikipedia.org/wiki/Why_the_lucky_stiff). Languages: *Java*, *C#*, *VB.net*, *Ruby*. * "**High School**": it goods if it work but it doesn't have to. Concentration on names like "SuperProgram 1.0 for Windows XP". (sorry - I haven't found good name but I mean the programmers who started mastering CS and are not good at it - at least yet). Languages: *PHP*, *VB*, *Ruby* * **New School Web Developers**: As above. Please note that: * it is possible to mix the cultures in organizations and in single person. In fact it often does. * The languages are **EXAMPLES** and it is for example quite large group of "hackers" working on C#. It is more of game of associations the real study so please don't be offended (yes - I do know that there are great programms written in PHP with good engeneering practice etc. but it tend to be first language for many people who don't know what for example XSS is) * I didn't want to offend anyone by name High School. I meant that it is often first step into programming via this culture (and hopefully not last) * ***Edit:*** **Academia** does not mean that person is in academia as well as being in academia does not mean that someone belongs to **academia** (despite being briliant scientist/researcher etc.). It denotes that he preferes the tools which gives clear, obviously correct solution even if it lacks performance/takes longer time/... Similary **Corporate** culture is not equivlent to corporations. I think I'm currently mostly Open Source with slight influence of Academia (passive).
Count me down as the 'old-school' guy. I never did LISP well, though. Emacs? Nah, `vi` and `set -o vi` in my shell for me thank you.
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
I represent the lonely contingent of Delphi Devs under 30. Our caucus is small, but our hearts are big.
**Academics that make research using computers, not research about computers.** They: - are writing software that can consume unlimited quantities of CPU time, memory and disc space so they care (or at least try to care) of performance, *either* by using stuff like `-O3`, `time`, profilers, memcheck, and spend hours more or less randomly changing the code to gather some speedup *or* mindlessly applying some mythical tricks to their scrips. - use real numbers and know that it is tricky enough so a separate science named "numerics" can exist. - often use some very specific programming languages/libraries/programs and are very fanatic about it; flame wars are common, mostly about performance. - call their programs "codes" to highlight that they have so obfuscated user interface so only their creators know how to use it. - usually work on Linux or at least use PuTTY to ssh to some Linux workstation/cluster.
6,005
To the outside world, programmers, computer scientists, software engineers, and developers may all seem alike, but that's far from the case for the people who create software for a living. Any single programmer's ability and knowledge can range very widely, as well as their tools (OS, language, and yes, preferred editor), and that diversity spawns many sub-cultures in software - like programmers who actively use Stack Overflow and this site, versus many more who don't. I'm curious to hear from others what software sub-cultures they've encountered, belonged to, admired, disliked, or even created. For starters, I've encountered: * **Microsoft-driven companies and developers**: their entire stack is from Redmond, WA. E-mail is Outlook is e-mail. The web is IE and IIS. They have large binders of their MS Developer Network subscription full of multiple versions of VB, .net, Visual Studio, etc. Avoids working with a shell/command-line. Don't see what the fuss with open-source and such is all about. MS-centric companies tend to be 9-5 and quite corporate (driven by business managers, not software people). Nowadays (given the wide availability of non-MS tools), this is the antithesis of hacker culture. * **Old-school CS people**: they often know Lisp and Unix extremely well; sometimes, they may have written a semi-popular Lisp themselves, or a system utility. Few, if any, "software engineering" things are new to them, nor are they impressed by such. Know the references, history, and higher-level implications of programming languages like Lisp, C, Prolog, and Smalltalk. Can be bitter about AI outcomes of the 80's and 90's. Tend to be Emacs users. Can type out multi-line shell commands without blinking an eye. Their advice can by cryptic, but contains gold once understood. * **New-school web developers**: played with computers and video games growing up, but often only really started programming in the late '90s or early '00's. Comfortable with 1 to 1.5 scripting/dynamic languages; think C and languages outside of Ruby/Perl/Python are unnecessary/magical. May have considered HTML as programming initially. Tend to get a Mac and be fanatical/irrational about it. Use frameworks more than build them. Often overly-enthusiastic about NoSQL and/or Ruby On Rails. * **New-school CS**: lots of training in statistics, Bayesian models and inference; don't say "AI," say "machine learning." More Java than Lisp, but could also be expert Haskell programmers. Seeing major real-world successes by experts in their field (Google, finance/quants) often makes them (over) confident. But big data, and the distributed processing of such, really are changing the world. The examples above are by no means complete, correct, orthogonal, or objective. :) Just what I've seen personally, and provided to spark some discussion and outline of the broader question. Feel free to disagree!
2010/09/21
[ "https://softwareengineering.stackexchange.com/questions/6005", "https://softwareengineering.stackexchange.com", "https://softwareengineering.stackexchange.com/users/2026/" ]
I'm kind of in the Alt.NET/old-school CS camp. I work with Microsoft tech (C#, etc.), but I'm aware that there's a whole world around me, other languages, algorithms, frameworks, "stuff under the hood", etc. Not perfect, obviously, but it's a work in progress.
Count me down as the 'old-school' guy. I never did LISP well, though. Emacs? Nah, `vi` and `set -o vi` in my shell for me thank you.
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
You want this: ``` return parseFloat($scope.x) + parseFloat($scope.y); ``` `+` overrides string concatenation when you have 2 strings. You'll need to cast them to integers or floats explicitly. `-`,`*`,`/` will all cast to numbers if possible.
That is because the concatenation has higher precedence over addition operation or the Plus (+) Operator. Since, Minus Operator (-) works just fine , here is a Simple Hack! ``` <script type="text/javascript"> function TodoCtrl($scope) { $scope.total = function () { //Subtracting a Zero converts the input to an integer number return (($scope.x - 0) + ($scope.y - 0)); }; } </script> ``` You could as well do this: ``` <form> <li>Number 1: <input type="text" ng-model="x" /> </li> <li>Number 2: <input type="text" ng-model="y" /> </li> <li>Total <input type="text" value="{{(x-0) + (y-0)}}"/></li> </form> ```
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
That is because the concatenation has higher precedence over addition operation or the Plus (+) Operator. Since, Minus Operator (-) works just fine , here is a Simple Hack! ``` <script type="text/javascript"> function TodoCtrl($scope) { $scope.total = function () { //Subtracting a Zero converts the input to an integer number return (($scope.x - 0) + ($scope.y - 0)); }; } </script> ``` You could as well do this: ``` <form> <li>Number 1: <input type="text" ng-model="x" /> </li> <li>Number 2: <input type="text" ng-model="y" /> </li> <li>Total <input type="text" value="{{(x-0) + (y-0)}}"/></li> </form> ```
Adding floating numbers in correct way ``` $scope.Total = parseFloat($scope.firstValue) + parseFloat($scope.secondValue); $scope.Total = parseFloat($scope.Total.toFixed(2)); ``` The $scope.Total now will display correctly in the view if binding with `ng-model` is applied for example if you have ``` $scope.firstValue = 10.01; $scope.firstValue = 0.7; ``` `$scope.Total = parseFloat($scope.firstValue) + parseFloat($scope.secondValue);` The variable `$scope.Total` will be `10.709999999999999` and this is not correct! Adding with parseFloat will not be enough for a correct value. But if you apply `$scope.Total = parseFloat($scope.Total.toFixed(2));` The value will result correctly: `$scope.Total = 10.71` Be careful will floating point numbers in javascript
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
You want this: ``` return parseFloat($scope.x) + parseFloat($scope.y); ``` `+` overrides string concatenation when you have 2 strings. You'll need to cast them to integers or floats explicitly. `-`,`*`,`/` will all cast to numbers if possible.
Adding floating numbers in correct way ``` $scope.Total = parseFloat($scope.firstValue) + parseFloat($scope.secondValue); $scope.Total = parseFloat($scope.Total.toFixed(2)); ``` The $scope.Total now will display correctly in the view if binding with `ng-model` is applied for example if you have ``` $scope.firstValue = 10.01; $scope.firstValue = 0.7; ``` `$scope.Total = parseFloat($scope.firstValue) + parseFloat($scope.secondValue);` The variable `$scope.Total` will be `10.709999999999999` and this is not correct! Adding with parseFloat will not be enough for a correct value. But if you apply `$scope.Total = parseFloat($scope.Total.toFixed(2));` The value will result correctly: `$scope.Total = 10.71` Be careful will floating point numbers in javascript
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
If that is indeed the case then what is happening is the values that are being passed in for x and y are being treated as strings and concatenated. What you should do is convert them to numbers using `parseInt` ``` return parseInt($scope.x) + parseInt($scope.y); ``` or if you prefer brevity ``` return $scope.x*1 + $scope.y*1; ```
Adding floating numbers in correct way ``` $scope.Total = parseFloat($scope.firstValue) + parseFloat($scope.secondValue); $scope.Total = parseFloat($scope.Total.toFixed(2)); ``` The $scope.Total now will display correctly in the view if binding with `ng-model` is applied for example if you have ``` $scope.firstValue = 10.01; $scope.firstValue = 0.7; ``` `$scope.Total = parseFloat($scope.firstValue) + parseFloat($scope.secondValue);` The variable `$scope.Total` will be `10.709999999999999` and this is not correct! Adding with parseFloat will not be enough for a correct value. But if you apply `$scope.Total = parseFloat($scope.Total.toFixed(2));` The value will result correctly: `$scope.Total = 10.71` Be careful will floating point numbers in javascript
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
You want this: ``` return parseFloat($scope.x) + parseFloat($scope.y); ``` `+` overrides string concatenation when you have 2 strings. You'll need to cast them to integers or floats explicitly. `-`,`*`,`/` will all cast to numbers if possible.
I advise you to change the type of your input to "number", then, you will not need to parse it, angular will convert it automatically to interger. I did it and it works, without a scope, but only to declare your {{total}}
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
If that is indeed the case then what is happening is the values that are being passed in for x and y are being treated as strings and concatenated. What you should do is convert them to numbers using `parseInt` ``` return parseInt($scope.x) + parseInt($scope.y); ``` or if you prefer brevity ``` return $scope.x*1 + $scope.y*1; ```
You want this: ``` return parseFloat($scope.x) + parseFloat($scope.y); ``` `+` overrides string concatenation when you have 2 strings. You'll need to cast them to integers or floats explicitly. `-`,`*`,`/` will all cast to numbers if possible.
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
Adding floating numbers in correct way ``` $scope.Total = parseFloat($scope.firstValue) + parseFloat($scope.secondValue); $scope.Total = parseFloat($scope.Total.toFixed(2)); ``` The $scope.Total now will display correctly in the view if binding with `ng-model` is applied for example if you have ``` $scope.firstValue = 10.01; $scope.firstValue = 0.7; ``` `$scope.Total = parseFloat($scope.firstValue) + parseFloat($scope.secondValue);` The variable `$scope.Total` will be `10.709999999999999` and this is not correct! Adding with parseFloat will not be enough for a correct value. But if you apply `$scope.Total = parseFloat($scope.Total.toFixed(2));` The value will result correctly: `$scope.Total = 10.71` Be careful will floating point numbers in javascript
I advise you to change the type of your input to "number", then, you will not need to parse it, angular will convert it automatically to interger. I did it and it works, without a scope, but only to declare your {{total}}
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
That is because the concatenation has higher precedence over addition operation or the Plus (+) Operator. Since, Minus Operator (-) works just fine , here is a Simple Hack! ``` <script type="text/javascript"> function TodoCtrl($scope) { $scope.total = function () { //Subtracting a Zero converts the input to an integer number return (($scope.x - 0) + ($scope.y - 0)); }; } </script> ``` You could as well do this: ``` <form> <li>Number 1: <input type="text" ng-model="x" /> </li> <li>Number 2: <input type="text" ng-model="y" /> </li> <li>Total <input type="text" value="{{(x-0) + (y-0)}}"/></li> </form> ```
I advise you to change the type of your input to "number", then, you will not need to parse it, angular will convert it automatically to interger. I did it and it works, without a scope, but only to declare your {{total}}
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
You want this: ``` return parseFloat($scope.x) + parseFloat($scope.y); ``` `+` overrides string concatenation when you have 2 strings. You'll need to cast them to integers or floats explicitly. `-`,`*`,`/` will all cast to numbers if possible.
To add two numbers together I would parse the string for Integers and check for null: ``` function TodoCtrl($scope) { $scope.total = function() { var firstNum = parseInt($scope.firstNum) var secondNum = parseInt($scope.secondNum); if (!firstNum) firstNum = 0; if (!secondNum) secondNum = 0; return firstNum + secondNum; } } ```
15,648,726
I am trying to always redirect people to ``` https://www.somedomain.com/URL ``` when they come in on a non secure port. This is because my SSL is for this url. When someone goes to <http://www.somedomain.com> they get sent to ``` http://www.www.somedomain.com ``` Here is the htaccess rewrite that i am trying: ``` RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} ``` Edit: I am using a cPanel server, so making additional hosts is not going to work.
2013/03/26
[ "https://Stackoverflow.com/questions/15648726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2213594/" ]
Make input type as number, since it is addition operation ``` <input type="text" ng-model="x" /> <input type="text" ng-model="y" /> ```
To add two numbers together I would parse the string for Integers and check for null: ``` function TodoCtrl($scope) { $scope.total = function() { var firstNum = parseInt($scope.firstNum) var secondNum = parseInt($scope.secondNum); if (!firstNum) firstNum = 0; if (!secondNum) secondNum = 0; return firstNum + secondNum; } } ```
11,076,467
Basically what I'm trying to do is get the information from column x no matter how many times it was mentioned. means that if I have this kind of table: ``` x | y | z ------+-------+-------- hello | one | bye hello | two | goodbye hi | three | see you ``` so what I'm trying to do is create a query that would get all of the names that are mentions in the x column without duplicates and put it into a select list. my goal is that I would have a select list with TWO not THREE options, hello and hi this is what I have so far which isn't working. hope you guys know the answer to that: ``` function getList(){ $options="<select id='names' style='margin-right:40px;'>"; $c_id = $_SESSION['id']; $sql="SELECT * FROM names"; $result=mysql_query($sql); $options.="<option value='blank'>-- Select something --</option>" ; while ($row=mysql_fetch_array($result)) { $name=$row["x"]; $options.="<option value='$name'>$name</option>"; } $options.= "</SELECT>"; return "$options"; } ``` Sorry for confusing... i edited my source
2012/06/18
[ "https://Stackoverflow.com/questions/11076467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/994705/" ]
You seem to be using only `x`. So you can just use query: ``` SELECT DISTINCT x FROM names ```
if this is your query ``` $sql="SELECT * FROM names"; $result=mysql_query($sql); ``` Then ``` $sql="SELECT DISTINCT x FROM names"; $result=mysql_query($sql); ``` Change \* to x if you want only one column as it is faster
3,931,485
I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: <http://api.hostip.info> but they just return XX when I test it. If anyone knows any better methods please share. Thanks.
2010/10/14
[ "https://Stackoverflow.com/questions/3931485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356372/" ]
I use this: ``` $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; $ip = $_SESSION['ip']; $try1 = "http://ipinfodb.com/ip_query.php?ip=".$ip."&output=xml"; $try2 = "http://backup.ipinfodb.com/ip_query.php?ip=".$ip."&output=xml"; $XML = @simplexml_load_file($try1,NULL,TRUE); if(!$XML) { $XML = @simplexml_load_file($try2,NULL,TRUE); } if(!$XML) { return false; } //Retrieve location, set time if($XML->City=="") { $loc = "Localhost / Unknown"; } else { $loc = $XML->City.", ".$XML->RegionName.", ".$XML->CountryName; } $_SESSION['loc'] = $loc; ```
You should use the [geoip library](http://php.net/manual/en/book.geoip.php). Maxmind provides free databases and commercial databases, with a difference in the date of last update and precision, the commercial being of better quality. See <http://www.maxmind.com/app/geolitecountry> for the free database. I think it should be sufficient for basic needs.
3,931,485
I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: <http://api.hostip.info> but they just return XX when I test it. If anyone knows any better methods please share. Thanks.
2010/10/14
[ "https://Stackoverflow.com/questions/3931485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356372/" ]
Try these: <http://ip-to-country.webhosting.info/> <http://www.ip2location.com/> Both are IP address-to-country databases, which allow you to look up the country of origin of a given IP address. However it's important to note that these databases are not 100% accurate. They're a good guide, but you will get false results for a variety of reasons. * Many people use proxying to get around country-specific blocks and filters. * Many IP ranges are assigned to companies with large geographic spread; you'll just get the country where they're based, not where the actual machine is (this always used to be a big problem for tracking AOL users, because they were all apparently living in Virginia) * Control of IP ranges are sometimes transferred between countries, so you may get false results from that (especially for smaller/less well-connected countries) Keeping your database up-to-date will mitigate some of these issues, but won't resolve them entirely (especially the proxying issue), so you should always allow for the fact that you will get false results.
You should use the [geoip library](http://php.net/manual/en/book.geoip.php). Maxmind provides free databases and commercial databases, with a difference in the date of last update and precision, the commercial being of better quality. See <http://www.maxmind.com/app/geolitecountry> for the free database. I think it should be sufficient for basic needs.
3,931,485
I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: <http://api.hostip.info> but they just return XX when I test it. If anyone knows any better methods please share. Thanks.
2010/10/14
[ "https://Stackoverflow.com/questions/3931485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356372/" ]
I use this: ``` $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; $ip = $_SESSION['ip']; $try1 = "http://ipinfodb.com/ip_query.php?ip=".$ip."&output=xml"; $try2 = "http://backup.ipinfodb.com/ip_query.php?ip=".$ip."&output=xml"; $XML = @simplexml_load_file($try1,NULL,TRUE); if(!$XML) { $XML = @simplexml_load_file($try2,NULL,TRUE); } if(!$XML) { return false; } //Retrieve location, set time if($XML->City=="") { $loc = "Localhost / Unknown"; } else { $loc = $XML->City.", ".$XML->RegionName.", ".$XML->CountryName; } $_SESSION['loc'] = $loc; ```
You can use Geolocation to get the Coordinates and then some Service to get the Country from that, but the geolocation API is browser based so you can only access it via JavaScript and then have to pass theese Informations to PHP somehow, i wrote something on the JS Part once: <http://www.lautr.com/utilizing-html5-geolocation-api-and-yahoo-placefinder-example> When it comes to getting the Location via the IP, there are a bazillion Services out there who offer databases for that, some free, some for charge, some with a lot of IP's stored and much data, some with less, for example the one you mentioned, works just fine: <http://api.hostip.info/?ip=192.0.32.10> So You can ether go with the Geolocation API which is pretty neat, but requires the users permission, works via JS and doesnt work in IE (so far) or have to look for a IPÜ Location Service that fits your needs :)
3,931,485
I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: <http://api.hostip.info> but they just return XX when I test it. If anyone knows any better methods please share. Thanks.
2010/10/14
[ "https://Stackoverflow.com/questions/3931485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356372/" ]
Try these: <http://ip-to-country.webhosting.info/> <http://www.ip2location.com/> Both are IP address-to-country databases, which allow you to look up the country of origin of a given IP address. However it's important to note that these databases are not 100% accurate. They're a good guide, but you will get false results for a variety of reasons. * Many people use proxying to get around country-specific blocks and filters. * Many IP ranges are assigned to companies with large geographic spread; you'll just get the country where they're based, not where the actual machine is (this always used to be a big problem for tracking AOL users, because they were all apparently living in Virginia) * Control of IP ranges are sometimes transferred between countries, so you may get false results from that (especially for smaller/less well-connected countries) Keeping your database up-to-date will mitigate some of these issues, but won't resolve them entirely (especially the proxying issue), so you should always allow for the fact that you will get false results.
You can use Geolocation to get the Coordinates and then some Service to get the Country from that, but the geolocation API is browser based so you can only access it via JavaScript and then have to pass theese Informations to PHP somehow, i wrote something on the JS Part once: <http://www.lautr.com/utilizing-html5-geolocation-api-and-yahoo-placefinder-example> When it comes to getting the Location via the IP, there are a bazillion Services out there who offer databases for that, some free, some for charge, some with a lot of IP's stored and much data, some with less, for example the one you mentioned, works just fine: <http://api.hostip.info/?ip=192.0.32.10> So You can ether go with the Geolocation API which is pretty neat, but requires the users permission, works via JS and doesnt work in IE (so far) or have to look for a IPÜ Location Service that fits your needs :)
3,931,485
I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: <http://api.hostip.info> but they just return XX when I test it. If anyone knows any better methods please share. Thanks.
2010/10/14
[ "https://Stackoverflow.com/questions/3931485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356372/" ]
I use this: ``` $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; $ip = $_SESSION['ip']; $try1 = "http://ipinfodb.com/ip_query.php?ip=".$ip."&output=xml"; $try2 = "http://backup.ipinfodb.com/ip_query.php?ip=".$ip."&output=xml"; $XML = @simplexml_load_file($try1,NULL,TRUE); if(!$XML) { $XML = @simplexml_load_file($try2,NULL,TRUE); } if(!$XML) { return false; } //Retrieve location, set time if($XML->City=="") { $loc = "Localhost / Unknown"; } else { $loc = $XML->City.", ".$XML->RegionName.", ".$XML->CountryName; } $_SESSION['loc'] = $loc; ```
**Try these:** $key="9dcde915a1a065fbaf14165f00fcc0461b8d0a6b43889614e8acdb8343e2cf15"; $ip= "198.168.1230.122"; $url = "<http://api.ipinfodb.com/v3/ip-city/?key=>$key&ip=$ip&format=xml"; // load xml file $xml = simplexml\_load\_file($url); // print the name of the first element echo $xml->getName() . " "; // create a loop to print the element name and data for each node foreach($xml->children() as $child) { ``` echo $child->getName() . ": " . $child . "<br />"; ``` }
3,931,485
I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: <http://api.hostip.info> but they just return XX when I test it. If anyone knows any better methods please share. Thanks.
2010/10/14
[ "https://Stackoverflow.com/questions/3931485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356372/" ]
I use this: ``` $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; $ip = $_SESSION['ip']; $try1 = "http://ipinfodb.com/ip_query.php?ip=".$ip."&output=xml"; $try2 = "http://backup.ipinfodb.com/ip_query.php?ip=".$ip."&output=xml"; $XML = @simplexml_load_file($try1,NULL,TRUE); if(!$XML) { $XML = @simplexml_load_file($try2,NULL,TRUE); } if(!$XML) { return false; } //Retrieve location, set time if($XML->City=="") { $loc = "Localhost / Unknown"; } else { $loc = $XML->City.", ".$XML->RegionName.", ".$XML->CountryName; } $_SESSION['loc'] = $loc; ```
There are many ways to do it as suggested by those earlier. But I suggest you take a look at the IP2 PHP library available at <https://github.com/ip2iq/ip2-lib-php> which we developed. You can use it like below: ``` <?php require_once("Ip2.php"); $ip2 = new \ip2iq\Ip2(); $country_code = $ip2->country('8.8.8.8'); //$country_code === 'US' ?> ``` It doesn't need any SQL or web service lookup just a local data file. It is faster than almost all other methods out there. The database is updated monthly you can download it for free. The only thing you will need to do for now if you need the country name in your language is map it to an associative array from something like this <https://gist.github.com/DHS/1340150>
3,931,485
I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: <http://api.hostip.info> but they just return XX when I test it. If anyone knows any better methods please share. Thanks.
2010/10/14
[ "https://Stackoverflow.com/questions/3931485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356372/" ]
Try these: <http://ip-to-country.webhosting.info/> <http://www.ip2location.com/> Both are IP address-to-country databases, which allow you to look up the country of origin of a given IP address. However it's important to note that these databases are not 100% accurate. They're a good guide, but you will get false results for a variety of reasons. * Many people use proxying to get around country-specific blocks and filters. * Many IP ranges are assigned to companies with large geographic spread; you'll just get the country where they're based, not where the actual machine is (this always used to be a big problem for tracking AOL users, because they were all apparently living in Virginia) * Control of IP ranges are sometimes transferred between countries, so you may get false results from that (especially for smaller/less well-connected countries) Keeping your database up-to-date will mitigate some of these issues, but won't resolve them entirely (especially the proxying issue), so you should always allow for the fact that you will get false results.
**Try these:** $key="9dcde915a1a065fbaf14165f00fcc0461b8d0a6b43889614e8acdb8343e2cf15"; $ip= "198.168.1230.122"; $url = "<http://api.ipinfodb.com/v3/ip-city/?key=>$key&ip=$ip&format=xml"; // load xml file $xml = simplexml\_load\_file($url); // print the name of the first element echo $xml->getName() . " "; // create a loop to print the element name and data for each node foreach($xml->children() as $child) { ``` echo $child->getName() . ": " . $child . "<br />"; ``` }
3,931,485
I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: <http://api.hostip.info> but they just return XX when I test it. If anyone knows any better methods please share. Thanks.
2010/10/14
[ "https://Stackoverflow.com/questions/3931485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356372/" ]
Try these: <http://ip-to-country.webhosting.info/> <http://www.ip2location.com/> Both are IP address-to-country databases, which allow you to look up the country of origin of a given IP address. However it's important to note that these databases are not 100% accurate. They're a good guide, but you will get false results for a variety of reasons. * Many people use proxying to get around country-specific blocks and filters. * Many IP ranges are assigned to companies with large geographic spread; you'll just get the country where they're based, not where the actual machine is (this always used to be a big problem for tracking AOL users, because they were all apparently living in Virginia) * Control of IP ranges are sometimes transferred between countries, so you may get false results from that (especially for smaller/less well-connected countries) Keeping your database up-to-date will mitigate some of these issues, but won't resolve them entirely (especially the proxying issue), so you should always allow for the fact that you will get false results.
There are many ways to do it as suggested by those earlier. But I suggest you take a look at the IP2 PHP library available at <https://github.com/ip2iq/ip2-lib-php> which we developed. You can use it like below: ``` <?php require_once("Ip2.php"); $ip2 = new \ip2iq\Ip2(); $country_code = $ip2->country('8.8.8.8'); //$country_code === 'US' ?> ``` It doesn't need any SQL or web service lookup just a local data file. It is faster than almost all other methods out there. The database is updated monthly you can download it for free. The only thing you will need to do for now if you need the country name in your language is map it to an associative array from something like this <https://gist.github.com/DHS/1340150>