encoding

How can I avoid putting the magic encoding comment on top of every UTF-8 file in Ruby 1.9?

血红的双手。 提交于 2019-12-29 03:26:05
问题 I have a Rails project with a lot of Cyrillic strings in it. It worked fine on Ruby 1.8, but Ruby 1.9 assumes source files are US-ASCII-encoded unless you provide an # encoding: utf-8 comment at the top of the source file. At that point the files are not considered US-ASCII . Is there a simpler way to tell Ruby "This application is UTF8-encoded. Please consider all and any included source files as UTF8 unless declared otherwise"? UPDATE: I wrote "How to insert the encoding: UTF-8 directive

proper/best type for storing latitude and longitude

ぐ巨炮叔叔 提交于 2019-12-29 02:33:31
问题 In a system level programming language like C, C++ or D, what is the best type/encoding for storing latitude and longitude? The options I see are: IEEE-754 FP as degrees or radians degrees or radians stored as a fixed point value in an 32 or 64 bit int mapping of an integer range to the degree range: -> deg = (360/2^32)*val degrees, minutes, seconds and fractional seconds stored as bit fields in an int a struct of some kind. The easy solution (FP) has the major down side that it has highly

Can not insert German characters in Postgres

邮差的信 提交于 2019-12-29 01:27:42
问题 I am using UTF8 as encoding for my Postgres 8.4.11 database: CREATE DATABASE test WITH OWNER = postgres ENCODING = 'UTF8' TABLESPACE = mydata LC_COLLATE = 'de_DE.UTF-8' LC_CTYPE = 'de_DE.UTF-8' CONNECTION LIMIT = -1; ALTER DATABASE test SET default_tablespace='mydata'; ALTER DATABASE test SET temp_tablespaces=mydata; And the output of \l test | postgres | UTF8 | de_DE.UTF-8 | de_DE.UTF-8 | When I try to insert a German character: create table x(a text); insert into x values('ä,ß,ö'); ERROR:

Convert escaped Unicode character back to actual character in PostgreSQL

自古美人都是妖i 提交于 2019-12-29 01:14:49
问题 Is there a way how I can convert the following string back to the human-readable value? I have some external data where all non-ascii characters are escaped. Example strings: 16 StringProvider_111=Telefon\u00ED kontakty 17 StringProvider_116=Odpov\u011Bdn\u00E1 osoba Required Result: 16 StringProvider_111=Telefoní kontakty 17 StringProvider_116=Odpovědná osoba SQLFiddle The database has UTF8 encoding and collation cs_CZ.UTF-8 回答1: One old trick is using parser for this purpose: postgres=#

Converting double slash utf-8 encoding

眉间皱痕 提交于 2019-12-28 22:02:54
问题 I cannot get this to work! I have a text file from a save game file parser with a bunch of UTF-8 Chinese names in it in byte form, like this in the source.txt: \xe6\x89\x8e\xe5\x8a\xa0\xe6\x8b\x89 But, no matter how I import it into Python (3 or 2), I get this string, at best: \\xe6\\x89\\x8e\\xe5\\x8a\\xa0\\xe6\\x8b\\x89 I have tried, like other threads have suggested, to re-encode the string as UTF-8 and then decode it with unicode escape, like so: stringName.encode("utf-8").decode("unicode

Clojure base64 encoding

北城以北 提交于 2019-12-28 13:45:10
问题 I want something as simple as "string" -> base64. With the older base64.encode-str it was easy (and sounded "more clojure", but the newer clojure.data.codec.base64 requires input and output streams and seems an ugly wrapper around Java way of doing things. So, what is the way, having a string, to get a base64 encoded array? Thanks 回答1: You can use encode function and pass array of bytes: (encode (.getBytes "Hello world!")) 回答2: Four years later, but I think this is worth mentioning if you're

Python unicode codepoint to unicode character

放肆的年华 提交于 2019-12-28 13:23:34
问题 I'm trying to write out to a flat file some Chinese, or Russian or various non-English character-sets for testing purposes. I'm getting stuck on how to output a Unicode hex-decimal or decimal value to its corresponding character. For example in Python, if you had a hard coded set of characters like абвгдежзийкл you would assign value = u"абвгдежзийкл" and no problem. If however you had a single decimal or hex decimal like 1081 / 0439 stored in a variable and you wanted to print that out with

Python unicode codepoint to unicode character

做~自己de王妃 提交于 2019-12-28 13:23:16
问题 I'm trying to write out to a flat file some Chinese, or Russian or various non-English character-sets for testing purposes. I'm getting stuck on how to output a Unicode hex-decimal or decimal value to its corresponding character. For example in Python, if you had a hard coded set of characters like абвгдежзийкл you would assign value = u"абвгдежзийкл" and no problem. If however you had a single decimal or hex decimal like 1081 / 0439 stored in a variable and you wanted to print that out with

How to set default encoding in Python (setdefaultencoding() function does not exist)? [duplicate]

半腔热情 提交于 2019-12-28 12:24:26
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Changing default encoding of python? I am reading dive in python and it mentions setting python's default encoding scheme in the XML parsing chapter. The setdefaultencoding is used in python-installed-dir/site-packages/pyanaconda/ sitecustomize.py import sys sys.setdefaultencoding('utf-8') But when I run the script, it raises: AttributeError: 'module' object has no attribute 'setdefaultencoding' How to set the

Is a base64 encoded string unique?

假如想象 提交于 2019-12-28 12:15:12
问题 I can't find an answer to this. If I encode a string with Base64 will the encoded output be unique based on the string? I ask because I want to create a token which will contain user information so I need make sure the output will be unique depending on the information. For example if I encode "UnqUserId:987654321 Timestamp:01/02/03" will this be unique so no matter what other userid I put it in there will never be a collision? 回答1: Two years late, but here we go: The short answer is yes,