I have a managed wiki based on Mediawiki.
The name of a typical page is Lab book 2018/01, and I want to extract the year (2018) and the month (02).
I can use #titleparts, but the issue is that it uses / as delimiters, so it returns either Lab book 2018, or 02.
How would I extract the year? i.e. just text from a string?
If you have the ParserFunctions extension installed, you can explode by any character https://www.mediawiki.org/wiki/Extension:StringFunctions##explode:
Related
I have a Python script which collects data and sends it to my MySQL table.
I noticed that the "Cost" sometimes is 0,95 which results in 0 in my table since my table use "0.95" instead of "0,95".
I assume the best solution is to convert the , to . in my Python script by using:
variable.replace(",", ".")
However, couldn't one solution be to change format in my MySQL table? So that I store numbers in this format:
1100
0,95
0,1
150000
My Django Model
cost = models.DecimalField(max_digits=10, decimal_places=4, default=None)
Any feedback on how to best solve this issue?
Thanks
Your first instinct is correct: convert the "unusual" (comma-decimal) input into the standard format that MySQL used by default (dot-decimal) at the first point where you receive it.
there's lots of ways to write numbers
Be careful, though that you don't get stung by people using commas as thousands separators like "3,203,907.23", or the European form "3.203.907,23", the Swiss "3'203'907,23' or even this form, which is widely used in India: "32,03,907.71" (yes, I did mean to type only two digits there!)
To make your life easier, the rule for currencies is relatively simple:
where a dot or comma is followed by only two digits at the end of the string, that character is acting as the decimal separator.
Once you know which is the decimal separator, you can safely remove all other non-digits from the string, change the decimal separator you found to . then use any standard library string-to-number conversion.
Storage format isn't presentation format
Yes, you can tell MySQL to use comma as its decimal separator, but doing that will break so much of your code - including the parts of the framework that read from the database and expect dot-decimal numbers - that you'll regret doing it that way very quickly...
There's a general principle at work here: you should do your data storage and processing using a format that is easy to process, interchangeable with other systems, and understood by other software developers.
Consider what happens if you need to allow a different framework to access your MySQL database to generate reports... whoever develops that software (and it may be you) will be glad that the numbers are all stored the way numbers are "always" stored in databases.
Convert on the way in, re-convert on the way out
Where you need to accept input in a different format, convert that input into your standardised format as early as possible.
When you need to use an output format, do the conversion to that format as late as possible.
The idea is to keep as much of your system "unexceptional" as possible. A programmer who has to remember what numeric format will in force at the time when a given method is called is not a happy programmer.
P.S.
The option you're talking about in MySQL is an example of this pattern: it doesn't change how numeric data is stored. All that changes is how you pass numbers to MySQL and how it presents them back to you.
What are examples of the Device ID unique to Windows Phones?
As I do not have a Windows phone, I cannot look up any values myself.
Specifically I'm wondering about the typical length of Advertising IDs that Windows uses that are similar to IDFAs/AppleIDs/AndroidIDs/GooglePlay/UDID/etc.
For example, IDFAs are strings that are 36 characters in length and have the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, where X = hexedecimal digit.
What is the similar format used by Windows Phones for unique IDs for advertisers?
The documentation simply states:
The advertising ID is represented as an alphanumeric string. When the advertising ID feature is turned off, this is an empty string.
The actual length of the string does not appear to be documented at present.
I would like to have a list of pages existing in wiktionary for a given word.
The case : I search the definition of the word მამა (means dad) in georgian. There is no page for this word in the georgian wiktionary so I would like to have a list of all synonyms.
I have searched and made test with this page :
https://en.wikipedia.org/wiki/Special:ApiSandbox#action=query&prop=revisions&format=json&rvprop=ids&rvlimit=10&titles=Foo&titles=Foo
Any idea?
Thanks for the help
There is no API for Wiktionary at the dictionary level, only at the wiki level, which is probably not much help. See this question for more details: How to retrieve Wiktionary word content?
So there is no API that will allow you to query for synonyms or even to query for Georgian language entries or data.
You can fetch Wiktionary pages either in raw wikitext or in HTML, and you can download entire database dumps in an XML format, which you can try to parse from scratch.
One thing that will help in the case of Georgian is that is has a unique alphabet so the vast majority of Wiktionary entries in the Georgian script will be for the Georgian language. (But there are also a very small number of entries for words in Laz, Mingrelian, Old Georgian, and Svan which will also use the Georgian script.)
I'm currently attempting to use HighStock charts on my site. I'll be using a PHP file to generate the data for the chart, my only question is what date/time format does HighStock use? Here's an example file they have on their site: http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json
[1107129600000,38.45]
Above is a line of data in the json file where 1107129600000 is the date and 38.45 is the stock price. Hopefully someone will know the date/time type. Thanks.
It looks like a UNIX timestamp. It's the number of seconds(or in your case, milliseconds) since January 1 1970. Most programming languages will let you convert this into more natural date/time formats.
Here's a tool to help you convert to see for yourself: http://www.epochconverter.com/
Further reference: http://en.wikipedia.org/wiki/Unix_time
according to the coldfusion docs SerializeJSON converts Dates to strings which can easily be parsed by JavaScript Date objects.
I just serialized a query and JavaScript could not parse the Date columns because the name of the month was serialized local specfic returning Mai, what is not understood by JavaScript. Javascript only accepts english month names. Do I now - as I just did - have to replace the local specific month name manually with it's english translation to easily parse the string to a JavaScript Date object?
Best,
Bernhard
You could try and deal with this on the server by using setLocale('en_us') to force English language versions of your query when serialised - not ideal but it might get the job done. I think this can be set per request. See info here: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fa3.html
Hope that helps.
This answer to another question suggests that perhaps you could use datejs and then use the appropriate localization to parse your strings natively rather than in English.
I have a solution
In the coldfusion administrator add this -Duser.language=en -Duser.region=US to the JVM agruments. (And restart the service) You tell the JVM engine not to use the machine locale but to use the 'normal' english locale.
When you use SerializeJSON after the change it will generate dates with the enlish month names.
I haven't found any unwanted side effects with this change.