not sure why i got this segmentation fault..
normal usage is okay, like when i search for country details . but when i use list, not sure if its overloaded or what, it just give a segmentation fault
Please enter country > Malaysia
Malaysia's Capital : Kuala Lumpur
Malaysia's Currency : Malaysian Ringgit
Malaysia's Currency Code : MYR
Malaysia's Region : Southeast Asia
Malaysia's Population : 22229040.00
Please enter country > russia
Russia's Capital : Moscow
Russia's Currency : Russian Ruble
Russia's Currency Code : RUB
Russia's Region : Asia
Russia's Population : 145470197.00
Please enter country > singapore
Singapore's Capital : Singapore
Singapore's Currency : Singapore Dollar
Singapore's Currency Code : SGD
Singapore's Region : Southeast Asia
Singapore's Population : 4300419.00
Please enter country > list
Country : Andorra
Country : United Arab Emirates
Country : Afghanistan
Country : Antigua and Barbuda
Country : Anguilla
Country : Albania
Country : Armenia
Country : Netherlands Antilles
Country : Angola
Country : Antarctica
Country : Argentina
Country : American Samoa
Country : Austria
Country : Australia
Country : Aruba
Country : Azerbaijan
Country : Bosnia and Herzegovina
Country : Barbados
Country : Bangladesh
Country : Belgium
Country : Burkina Faso
Country : Bulgaria
Country : Bahrain
Country : Burundi
Country : Benin
Country : Bermuda
Country : Brunei Darussalam
Country : Bolivia
Country : Brazil
Country : The Bahamas
Country : Bhutan
Country : Bouvet Island
Country : Botswana
Country : Belarus
Country : Belize
Country : Canada
Country : Cocos (Keeling) Islands
Country : Congo
Country : Central African Republic
Country : Congo
Country : Switzerland
Country : Cote d'Ivoire
Country : Cook Islands
Country : Chile
Country : Cameroon
Country : China
Country : Colombia
Country : Costa Rica
Country : Cuba
Country : Cape Verde
Country : Christmas Island
Country : Cyprus
Country : Czech Republic
Country : Germany
Country : Djibouti
Country : Denmark
Country : Dominica
Country : Dominican Republic
Country : Algeria
Country : Ecuador
Country : Estonia
Country : Egypt
Country : Western Sahara
Country : Eritrea
Country : Spain
Country : Ethiopia
Country : Finland
Country : Fiji
Country : Falkland Islands (Islas Malvinas)
Country : Micronesia
Country : Faroe Islands
Country : France
Country : France
Country : Gabon
Country : Grenada
Country : Georgia
Country : French Guiana
Country : Guernsey
Country : Ghana
Country : Gibraltar
Country : Greenland
Country : The Gambia
Country : Guinea
Country : Guadeloupe
Country : Equatorial Guinea
Country : Greece
Country : South Georgia and the South Sandwich Islands
Country : Guatemala
Country : Guam
Country : Guinea-Bissau
Country : Guyana
Country : Hong Kong (SAR)
Country : Heard Island and McDonald Islands
Country : Honduras
Country : Croatia
Country : Haiti
Country : Hungary
Country : Indonesia
Country : Ireland
Country : Israel
Country : Man
Country : India
Country : British Indian Ocean Territory
Country : Iraq
Country : Iran
Country : Iceland
Country : Italy
Country : Jersey
Country : Jamaica
Country : Jordan
Country : Japan
Country : Kenya
Country : Kyrgyzstan
Country : Cambodia
Country : Kiribati
Country : Comoros
Country : Saint Kitts and Nevis
Country : Korea
Country : Korea
Country : Kuwait
Country : Cayman Islands
Country : Kazakhstan
Country : Laos
Country : Lebanon
Country : Saint Lucia
Country : Liechtenstein
Country : Sri Lanka
Country : Liberia
Country : Lesotho
Country : Lithuania
Country : Luxembourg
Country : Latvia
Country : Libya
Country : Morocco
Country : Monaco
Country : Moldova
Country : Madagascar
Country : Marshall Islands
Country : Macedonia
Country : Mali
Country : Burma
Country : Mongolia
Country : Macao
Country : Northern Mariana Islands
Country : Martinique
Country : Mauritania
Country : Montserrat
Country : Malta
Country : Mauritius
Country : Maldives
Country : Malawi
Country : Mexico
Country : Malaysia
Country : Mozambique
Country : Namibia
Country : New Caledonia
Country : Niger
Country : Norfolk Island
Country : Nigeria
Country : Nicaragua
Country : Netherlands
Country : Norway
Country : Nepal
Country : Nauru
Country : Niue
Country : New Zealand
Country : Oman
Country : Panama
Country : Peru
Country : French Polynesia
Country : Papua New Guinea
Country : Philippines
Country : Pakistan
Country : Poland
Country : Saint Pierre and Miquelon
Country : Pitcairn Islands
Country : Puerto Rico
Country : Palestinian Territory
Country : Portugal
Country : Palau
Country : Paraguay
Country : Qatar
Country : Romania
Country : Russia
Country : Rwanda
Country : Saudi Arabia
Country : Solomon Islands
Country : Seychelles
Country : Sudan
Country : Sweden
Country : Singapore
Country : Saint Helena
Country : Slovenia
Country : Svalbard
Country : Slovakia
Country : Sierra Leone
Country : San Marino
Country : Senegal
Country : Somalia
Country : Suriname
Country : El Salvador
Country : Syria
Country : Swaziland
Country : Turks and Caicos Islands
Country : Chad
Country : French Southern and Antarctic Lands
Country : Togo
Country : Thailand
Country : Tajikistan
Country : Tokelau
Country : Turkmenistan
Country : Tunisia
Country : Tonga
Country : East Timor
Country : Turkey
Country : Trinidad and Tobago
Country : Tuvalu
Country : Taiwan
Country : Tanzania
Country : Ukraine
Country : Uganda
Country : United Kingdom
Country : United States Minor Outlying Islands
Country : United States
Country : Uruguay
Country : Uzbekistan
Country : Holy See (Vatican City)
Country : Saint Vincent and the Grenadines
Country : Venezuela
Country : British Virgin Islands
Country : Virgin Islands
Country : Vietnam
Country : Vanuatu
Country : Wallis and Futuna
Country : Samoa
Country : Yemen
Country : Mayotte
Country : Yugoslavia
Country : South Africa
Country : Zambia
Country : Zimbabwe
Segmentation fault (core dumped)
root#ubuntu:/home/baoky/05AUG-2012-COMPLETED/shell_assn2#
Below is my Client.cpp code
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h> /* for sockaddr_un struct*/
#define DEFAULT_PROTOCOL 0
/* POSIX renames "Unix domain" as "local IPC."
Not all systems define AF_LOCAL and PF_LOCAL (yet). */
#ifndef AF_LOCAL
#define AF_LOCAL AF_UNIX
#endif
#ifndef PF_LOCAL
#define PF_LOCAL PF_UNIX
#endif
using namespace std;
int readLine (int fd, char* str)
{
int n;
do /* Read characters until NULL or end-of-input */
{
}
return (n > 0); /* Return false if end-of-input */
}
void readServer(int fd) //Read Server output
{
char str[20000];
while (readLine (fd, str)) //Read lines till end of input
{
printf("\n%s\n",str);
return;
}
}
/****************************************************************/
int main ()
{
int clientFd, serverLen, result;
struct sockaddr_un serverAddress;
struct sockaddr* serverSockAddrPtr;
serverSockAddrPtr = (struct sockaddr*) &serverAddress;
serverLen = sizeof (serverAddress);
string buffer;
/* Create a socket, bidirectional, default protocol */
clientFd = socket (AF_LOCAL, SOCK_STREAM, DEFAULT_PROTOCOL);
serverAddress.sun_family = AF_LOCAL; /* Server domain */
do /* Loop until a connection is made with the server */
{
result = connect (clientFd, serverSockAddrPtr, serverLen);
if (result == -1) sleep (1); /* Wait and then try again */
}
while (result == -1);
//by here, connection would be established with server
printf("%s\n",'++++++++++++++++++++++++++++++++++++++++++++++++");
printf('\n");
string sendToServer;
while(1)
{
//null the string sendToServer
sendToServer = "";
cin << "Please enter country > ";
//get user input as sendToServer
getline(cout, sendToServer);
if(sendToServer!="")
{
//if not blank
//send to server
write (clientFd, sendToServer.c_str(), strlen (sendToServer.c_str()) + 1);
if ( sendToServer == "END" || sendToServer == "end")
{
//break out of while loop
break;
}//end if
readServer (clientFd); /* Read Server Response */
}//end if not blank
else
{
//print error message in bold red
}
}//end inner while
//if client type end, it will run to here.
close (cfentFd); /* Close the socket */
return 0;
}
Debugging Findout:
I realize if i cut short the countries.txt to about 20 records instead, no segmentation error. what could i do to maybe using a string instead of C string?
how do i use a string instead of char [200]
Thanks! or what could I do to fix the issue
Resolved:
change char to 20000 instead of 2000
When you send a string over a socket ... you do not necessarily get the null terminator unless you explicitly write it in the socket.
I suspect that's what's happening - your strings aren't getting terminated correctly.
IMHO...
STRONG SUGGESTION:
Fire up the debugger, and step through the inner loop in "readLine()". Make sure it's not an infinite loop ;)
Related
Hi I have nominatim installed on a ubuntu VM which I use for reverse geo-lookup. All is going well, but nominatim doesn't return the correct object when I do a reverse lookup for a highway entrance (motorway_link):
I found a github issues thread from 2 years ago providing solutions. One of the solutions being changing the address rank for motorway_links from 27 to 26 and the other one being altering the style import file. None of these seem to work for me. Has anyone had any expierence with this? I'm using the latest version of nominatim.
This is the highway section of my Nominatim/settings/import-full.style file:
{
"keys" : ["highway"],
"values" : {
"no" : "skip",
"turning_circle" : "skip",
"mini_roundabout" : "skip",
"noexit" : "skip",
"crossing" : "skip",
"give_way" : "skip",
"stop" : "skip",
"street_lamp" : "main,with_name",
"traffic_signals" : "main,with_name",
"service" : "main,with_name",
"cycleway" : "main,with_name",
"path" : "main,with_name",
"footway" : "main,with_name",
"steps" : "main,with_name",
"bridleway" : "main,with_name",
"track" : "main,with_name",
"byway": "main,with_name",
"motorway_link" : "main",
"trunk_link" : "main",
"primary_link" : "main",
"secondary_link" : "main",
"tertiary_link" : "main",
"" : "main"
}
Content of the highway section of nominatim/settings/import-address.style:
{
"keys" : ["highway"],
"values" : {
"motorway" : "main",
"trunk" : "main",
"primary" : "main",
"secondary" : "main",
"tertiary" : "main",
"unclassified" : "main",
"residential" : "main",
"living_street" : "main",
"pedestrian" : "main",
"road" : "main",
"service" : "main,with_name",
"cycleway" : "main,with_name",
"path" : "main,with_name",
"footway" : "main,with_name",
"steps" : "main,with_name",
"bridleway" : "main,with_name",
"track" : "main,with_name",
"byway": "main,with_name",
"motorway_link" : "main",
"trunk_link" : "main,with_name",
"primary_link" : "main,with_name",
"secondary_link" : "main,with_name",
"tertiary_link" : "main,with_name"
}
highway section of nominatim/settings/address-levels.json:
"highway" : {
"" : 30,
"service" : 27,
"cycleway" : 27,
"path" : 27,
"footway" : 27,
"steps" : 27,
"bridleway" : 27,
"motorway_link" : 26,
"primary_link" : 27,
"trunk_link" : 27,
"secondary_link" : 27,
"tertiary_link" : 27,
"residential" : 26,
"track" : 26,
"unclassified" : 26,
"tertiary" : 26,
"secondary" : 26,
"primary" : 26,
"living_street" : 26,
"trunk" : 26,
"motorway" : 26,
"pedestrian" : 26,
"road" : 26,
"construction" : 26
},
So I have solved. If you look in the nominatim/settings/env.defaults file, you'll see the following lines of code:
# Configuration file for OSM data import.
# This may either be the name of one of an internal style or point
# to a file with a custom style.
# Internal styles are: admin, street, address, full, extratags
NOMINATIM_IMPORT_STYLE=extratags
This means that you'll need to alter the extratags-import.style file to allow unnamed motorway_links aswell.
So change the highway section in nominatim/settings/extratags-import.style from this:
{
"keys" : ["highway"],
"values" : {
"no" : "skip",
"turning_circle" : "skip",
"mini_roundabout" : "skip",
"noexit" : "skip",
"crossing" : "skip",
"give_way" : "skip",
"stop" : "skip",
"street_lamp" : "main,with_name",
"traffic_signals" : "main,with_name",
"service" : "main,with_name",
"cycleway" : "main,with_name",
"path" : "main,with_name",
"footway" : "main,with_name",
"steps" : "main,with_name",
"bridleway" : "main,with_name",
"track" : "main,with_name",
"byway": "main,with_name",
"motorway_link" : "main,with_name",
"trunk_link" : "main,with_name",
"primary_link" : "main,with_name",
"secondary_link" : "main,with_name",
"tertiary_link" : "main,with_name",
"" : "main"
}
to this:
{
"keys" : ["highway"],
"values" : {
"no" : "skip",
"turning_circle" : "skip",
"mini_roundabout" : "skip",
"noexit" : "skip",
"crossing" : "skip",
"give_way" : "skip",
"stop" : "skip",
"street_lamp" : "main,with_name",
"traffic_signals" : "main,with_name",
"service" : "main,with_name",
"cycleway" : "main,with_name",
"path" : "main,with_name",
"footway" : "main,with_name",
"steps" : "main,with_name",
"bridleway" : "main,with_name",
"track" : "main,with_name",
"byway": "main,with_name",
"motorway_link" : "main",
"trunk_link" : "main",
"primary_link" : "main",
"secondary_link" : "main",
"tertiary_link" : "main",
"" : "main"
}
Altering these lines of code tells nominatim to not skipp unnamed motorway_links during import.
So if you find yourself having the same issue. Do the following things:
Go to the highway section in nominatim/settings/adress-levels.json and change the address rank of 'motorway_link' from 27 to 26
In the highway section of the import style files (import-full.style, import-address.style, extratags-import.style) change "motorway_link" : "main,with_name" to "motorway_link" : "main"
Reimport the data
This is my code example:
budi = {"Name" : "Budi", "Gender" : "Male", "Age" : 18}
ahmad = {"Name" : "Ahmad", "Gender" : "Male", "Age" : 7}
ika = {"Name" : "Ika", "Gender" : "Female", "Age" : 18}
marged = [budi, ahmad, ika]
I want the results like this, for example based on the 18 year old:
The oldest participants are: Budi and Ika
Here is the code according to what have you asked in the question. Please go through this very simple implementation.
from operator import itemgetter
budi = {"Name" : "Budi", "Gender" : "Male", "Age" : 1}
ahmad = {"Name" : "Ahmad", "Gender" : "Male", "Age" : 7}
ika = {"Name" : "Ika", "Gender" : "Female", "Age" : 18}
marged = [budi, ahmad, ika]
newlist = sorted(marged, key=itemgetter('Age'), reverse=True)
maxAge = newlist[0]["Age"]
finalList = [newlist[0]["Name"]]
for person in newlist[1:]:
if person["Age"] == maxAge:
finalList.append(person["Name"])
if len(finalList) == 1:
print "The oldest participant is: " + finalList[0]
else:
print "The oldest participants are: ",
for name in finalList:
print name+" ",
(Using Rails 4 ) I am trying to display the bootstrap3 datetimepicker in the current locale , it's working fine in english , but when I try to insert the require locale file in the application.js ( as stated in the doc) , I get an error :
[Error] TypeError: undefined is not an object (evaluating '$.fn.datetimepicker.dates')
(anonymous function) (application.js, line 15026)
in my assets, the application.js , I have :
//= require jquery
//= require jquery_ujs
//= require bootstrap.min
//= require moment
//= require bootstrap-datetimepicker
//= require pickers
// You may include any languages (optional)
//= require locales/bootstrap-datetimepicker.fr
the bootstrap-datetimepicker.fr.js file is the following :
;(function($){
$.fn.datetimepicker.dates['fr'] = {
days: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
daysShort: ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"],
daysMin: ["D", "L", "Ma", "Me", "J", "V", "S", "D"],
months: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
monthsShort: ["Jan", "Fev", "Mar", "Avr", "Mai", "Jui", "Jul", "Aou", "Sep", "Oct", "Nov", "Dec"],
today: "Aujourd'hui"
};
}(jQuery));
maybe this javascript content is not right... but why ? or is there another issue ?
problem is not with the datetimepicker as it's displayed correctly in english ( default)
withe this latest version, using moments.js ... I SHOUDL use the moments locales !!!
so my bootstrap-datetimepicker.fr.js should be :
// moment.js locale configuration
// locale : french (fr)
// author : John Fischer : https://github.com/jfroffice
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['moment'], factory); // AMD
} else if (typeof exports === 'object') {
module.exports = factory(require('../moment')); // Node
} else {
factory(window.moment); // Browser global
}
}(function (moment) {
return moment.defineLocale('fr', {
months : 'janvier_février_mars_avril_mai_juin_juillet_août_septembre_octobre_novembre_décembre'.split('_'),
monthsShort : 'janv._févr._mars_avr._mai_juin_juil._août_sept._oct._nov._déc.'.split('_'),
weekdays : 'dimanche_lundi_mardi_mercredi_jeudi_vendredi_samedi'.split('_'),
weekdaysShort : 'dim._lun._mar._mer._jeu._ven._sam.'.split('_'),
weekdaysMin : 'Di_Lu_Ma_Me_Je_Ve_Sa'.split('_'),
longDateFormat : {
LT : 'HH:mm',
L : 'DD/MM/YYYY',
LL : 'D MMMM YYYY',
LLL : 'D MMMM YYYY LT',
LLLL : 'dddd D MMMM YYYY LT'
},
calendar : {
sameDay: '[Aujourd\'hui à] LT',
nextDay: '[Demain à] LT',
nextWeek: 'dddd [à] LT',
lastDay: '[Hier à] LT',
lastWeek: 'dddd [dernier à] LT',
sameElse: 'L'
},
relativeTime : {
future : 'dans %s',
past : 'il y a %s',
s : 'quelques secondes',
m : 'une minute',
mm : '%d minutes',
h : 'une heure',
hh : '%d heures',
d : 'un jour',
dd : '%d jours',
M : 'un mois',
MM : '%d mois',
y : 'un an',
yy : '%d ans'
},
ordinal : function (number) {
return number + (number === 1 ? 'er' : '');
},
week : {
dow : 1, // Monday is the first day of the week.
doy : 4 // The week that contains Jan 4th is the first week of the year.
}
});
}));
I'm having problem storing lists of embedded documents/objects in MongoDB using the Grails MongoDB plugin. I used the information given in the documentation in chapter 3 but only got the embedding of one object working.
For testing purposes I created two domain objects Person and Address in a new Grails project. They look like this:
class Person {
ObjectId id
String firstName
String lastName
Address address
List otherAddresses = []
static embedded = ['address', 'otherAddresses']
}
class Address {
String street
String postCode
String city
}
When I execute the following lines in Bootstrap.groovy it stores two Person objects in MongoDB - both have a correct address but in person1 the otherAddresses List is "[ null ]" and in person2 the otherAddresses List is "[ { "street" : "Second Street. 164" , "city" : "New York" , "postCode" : "13579"}]"
def address = new Address(street: "Mainstreet. 164", city: "New York", postCode:"12345")
def person1 = new Person(firstName: "John", lastName: "Doe")
person1.address = address
person1.otherAddresses.add(address)
println person1.otherAddresses // Result: "[mongoembeddedlisttest.Address : (unsaved)]"
person1.save()
person1.errors.allErrors.each { println it } // no errors
def person2 = new Person(firstName: "Jane", lastName: "Doe")
person2.otherAddresses += ['street': 'Second Street. 164', 'city': 'New York', 'postCode':'13579']
println person2.otherAddresses // Result: "[[street:Second Street. 164, city:New York, postCode:13579]]"
person2.save()
Resulting Database Entries:
{ "_id" : { "$oid" : "521089461a150b20390d61c2"} , "address" : { "city" : "New York" , "postCode" : "12345" , "street" : "Mainstreet. 164"} , "firstName" : "John" , "lastName" : "Doe" , "otherAddresses" : [ null ] , "version" : 0}
{ "_id" : { "$oid" : "521089461a150b20390d61c3"} , "firstName" : "Jane" , "lastName" : "Doe" , "otherAddresses" : [ { "street" : "Second Street. 164" , "city" : "New York" , "postCode" : "13579"}] , "version" : 0}
Further Notes:
I'm using a pure mongodb approach (no a hybrid together with Hibernate)
I'm working on a Windows 8 machine using Grails 2.2.1 running mongo db 2.4.4
Person is a domain object in /grails-app/domain and Address is a "normal" groovy class in /src/groovy (I can put it in domain folder but that has no effect)
Everything is set to be nullable in Config.groovy: grails.gorm.default.constraints = { '*'(nullable: true) }
BuildConfig.groovy has the plugin entry: compile ":mongodb:1.3.0"
What am I doing wrong? How can I store a list of embedded objects using the Grails mechanism?
I think you're adding a map in the second person instead of an Address object. Is there any reason why you're adding the otherAddress different for each person?
I think this should work although I haven't tested it:
def address = new Address(street: "Mainstreet. 164", city: "New York", postCode:"12345")
def person1 = new Person(firstName: "John", lastName: "Doe")
person1.address = address
person1.otherAddresses.add(address)
println person1.otherAddresses // Result: "[mongoembeddedlisttest.Address : (unsaved)]"
person1.save()
person1.errors.allErrors.each { println it } // no errors
def person2 = new Person(firstName: "Jane", lastName: "Doe")
person2.otherAddresses += new Address('street': 'Second Street. 164', 'city': 'New York', 'postCode':'13579')
println person2.otherAddresses
person2.save()
In my program I have to display prices for different countries. To do this, I generate a special formatting class for each country (using open web services):
public class Country
{
...
// autogenerated with T4
public static readonly List<Country> Countries = new List<Country>
{
new Country
{
CountryCode = "us",
CallingCode = "1",
CountryName = "United States",
CountryCodeNumeric = "840",
CountryCodeA3 = "usa",
CurrencySymbol = "$",
Continent = "NA",
ContinentName = "North America",
Capital = "Washington",
CurrencyCode = "USD",
...
},
...
But I also need currency symbol location to display prices properly. For example: I can place currency symbol before or after the price: 8.40 € and € 8.40.
Is there any web service or another reliable source, which I can use to get currency symbol positions?