converter

Python MySQLdb converters isn't working

 ̄綄美尐妖づ 提交于 2019-12-05 08:54:34
I'm trying to run an ETL script using python and MySQLdb but I'm stuck with the results from my initial extract query. The types returned are all Long and Decimal when I want Int and Float. I've searched around for a few hours trying to get an answer to this without any success. database = MySQLdb.connect(host='db',user='user', passwd='password', db='db123') database_cursor = database.cursor() database_query = ("SELECT id, siteId, campaignId, hour, sum(impressions) AS impressions, " "sum(clicks) AS clicks, sum(conversions) AS conversions, sum(costs/1000000) AS revenue " "FROM database.DM

XStream: Collapsing XML hierarchy as I parse

北城余情 提交于 2019-12-05 07:15:28
I have an XML document (generated by Adobe XFA forms), that contains data like the following: <Position> <PositionBorder> <Title/> <StartDate/> <EndDate/> </PositionBorder> </Position> Since this file is defined elsewhere, I am not at liberty to change the format of the XML that I get. In my Java code, I create a Position class that contains the Title, Start and End Dates. My problem is, when I use XStream to parse the file, it wants a PositionBorder class to hold the title and dates. I want to basically ignore the border and place all of the fields into the Position class. What I'd really

Primefaces autocomplete with POJO and String value [duplicate]

孤者浪人 提交于 2019-12-05 06:10:42
问题 This question already has answers here : p:autoComplete itemLabel throws “The class 'java.lang.String' does not have the property 'label'.” (5 answers) Closed 3 years ago . I need to have an autocomplete with string value, because users can't be restricted to provided items by autocomplete method, but they should be able to write anything in the search field. If they want, they can choose from suggestions as well. Now I am always getting /archive/overview.xhtml @28,57 itemLabel="#{item.name}"

Static Instance Base/Derived class

自古美人都是妖i 提交于 2019-12-05 06:07:06
I would like to write a static instance property in a base class and derive this, but I am facing some problems. Here is the code for the base class - I currently have: public abstract class ResourceInstance<T> { private static T _instance; public static T Instance { get { if (_instance != null) return _instance; var method = MethodBase.GetCurrentMethod(); var declaringType = method.DeclaringType; if (declaringType != null) { var name = declaringType.Name; _instance = (T)Application.Current.TryFindResource(name); } return _instance; } } } As you can see its primary use is for WPF Resources

@Convert on @Id field

我的梦境 提交于 2019-12-05 05:56:16
I'm trying to @Id @Column(name = "MY_ID_FIELD") @Convert(converter = IdConverter.class) private Long id; IdConverter is: @Converter public class IdConverter implements AttributeConverter<Long, BigDecimal> { @Override public BigDecimal convertToDatabaseColumn(Long attribute) { return BigDecimal.valueOf(attribute); } @Override public Long convertToEntityAttribute(BigDecimal dbData) { return dbData.longValue(); } } The converter will map BigDecimal, the attribute field type Hibernate expects given that in the sql server database the id column type is numeric, to Long. I'm using Spring Data Jpa

Converting Arabic numerals to Arabic/Persian numbers in html file

元气小坏坏 提交于 2019-12-05 05:16:58
问题 I am trying to convert the plain text Arabic Numerals into Eastern Arabic digits. So basically taking 1 2 3... and converting them into ١‎ ٢‎ ٣‎... . The function converts all numbers, including any numbers contained within tags, i.e. H1 . private void LoadHtmlFile(object sender, EventArgs e) { var htmlfile = "<html><body><h1>i was born in 1988</h1></body></html>".ToArabicNumber(); ; webBrowser1.DocumentText=htmlfile; } } public static class StringHelper { public static string ToArabicNumber

How to set date format for JSON converter in Grails

社会主义新天地 提交于 2019-12-05 04:06:07
I've a method in my Grails controller that should return a JSON, a property of the JSON is a Date object, but when I do: render myObject as JSON the output is like: { "dateProperty": "2010-12-31T23:00:00Z", "otherProperty" : "aValue..." } Is there a way to change the default date format used from the converter? I've tried to set the property grails.converters.json.date and also grails.date.formats in the Config.groovy , but this doesn't work. Am I doing something wrong or is there another way to do it? Thanks I generally use a custom Marshaller. Assume you have the following Domain class

WPF converter to update in real time background colour of textbox on text change

一笑奈何 提交于 2019-12-05 03:34:47
I have two textboxes for the firstname and second name of a user and I have created a converter to change the background colour of the textbox when the text equals a specific string. The problem I am having is that the textbox will only update at run time and doesn't update when I change the text is the textbox. XAML: <TextBox x:Name="forenameTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="1" Background="{Binding Staff,Converter ={StaticResource StaffNameToBackgroundColourConverter1}}" Text="{Binding Staff.Forename, Mode=TwoWay, NotifyOnValidationError=true

Faster way to convert byte array to int

[亡魂溺海] 提交于 2019-12-05 02:59:36
问题 Is there a faster way than BitConverter.ToInt32 to convert a byte array to an int value? 回答1: If I remember correctly, that implementation uses unsafe code (treating a byte* as an int*), so it will be hard to beat, but the other alternative is shifting. However, from lots of work in this area, this is so unlikely to be a genuine bottleneck as to be irrelevant. I/O is the main issue, typically. GetBytes(int), however, is more expensive (in high volume) due to array / heap allocation. 回答2: I

Naudio - Convert 32 bit wav to 16 bit wav

半城伤御伤魂 提交于 2019-12-05 02:11:33
问题 I've been trying to convert a 32 bit stereo wav to 16 bit mono wav. I use naudio to capture the sound I and thought that using just the two of four more significant bytes will work. Here is the DataAvailable implementation: void _waveIn_DataAvailable(object sender, WaveInEventArgs e) { byte[] newArray = new byte[e.BytesRecorded / 2]; short two; for (int i = 0, j = 0; i < e.BytesRecorded; i = i + 4, j = j + 2) { two = (short)BitConverter.ToInt16(e.Buffer, i + 2); newArray[j] = (byte)(two &