w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
App crashes while converting to Objective-C ARC
Your original code is not correct. You're telling the compiler that it's safe to use a ABMultiValueRef as an NSString -- and it isn't. I've not tried this but, something like this might work better: ABMultiValueRef phones =(ABMultiValueRef)CFBridgingRelease(ABRecordCopyValue(record, kABPersonPhoneProperty)); NSString* num = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones, 0);

Categories : Objective C

iOS/Objective C: Converting RGB Data to UIImage
Here is Conversion of NSData to UIImage : NSData *imageData = UIImagePNGRepresentation(image); UIImage *image=[UIImage imageWithData:data]; I have created PNG image using this code, hope it will works for you also.

Categories : IOS

Converting date from SQLite manager to real time (mountain standard time)
Try this: SELECT datetime(399082293, 'unixepoch', 'localtime'); the result given for me is: 1982-08-25 01:11:33 There is more information about various date formatting options in SQLite on this page.

Categories : Sqlite

Jodatime converting time zoned date time to millis
A few points: You don't need to call System.currentTimeMillis(). Just pass this: DateTime utc = new DateTime(DateTimeZone.UTC); When you call .getMillis() the result is always in UTC. Representing time as an integer that is not UTC-based is a bad idea, and not something that Joda Time will provide. Your assessment that the milliseconds are affected by your local time zone is incorrect. The conversion errors are because of how you are calling format.print. When you pass an integer, the default behavior is to use the current time zone, which is you local time. You can change it like this: format.withZone(DateTimeZone.UTC).print(current) However, if the intention is to print it as a date string, why go to milliseconds first anyway? If you pass the original DateTime,

Categories : Java

converting JSON python time to regular time
datetime.fromtimestamp from the datetime module should do it. For example: >>> from datetime import datetime >>> d = datetime.fromtimestamp(1358294533) >>> d.isoformat() '2013-01-15T19:02:13' For getting a more controlled string representation of the datetime use the datetime.strftime function.

Categories : Python

Translate objective-c into ruby
You'll have to work out the Ruby side of things yourself, but this line of code: [self presentSemiViewController:semiVC withOptions:@{ KNSemiModalOptionKeys.pushParentBack : @(YES), KNSemiModalOptionKeys.animationDuration : @(0.3), KNSemiModalOptionKeys.shadowOpacity : @(0.8), }]; Is the same as this: NSDictionary *dict = [NSDictionary, dictionaryWithObjectsAndKeys: [NSNumber numberWithBOOL:YES], KNSemiModalOptionKeys.pushParentBack, [NSNumber numberWithFloat:0.3], KNSemiModalOptionKeys.animationDuration, [NSNumber numberWithFloat:08], KNSemiModalOptionKeys.shadowOpacity]; [self presentSemiViewController:semiVC withOptions:dict]; Assuming that KNSemiModalOptionKeys.pushParentBack is using dot notation to execute a method, each of those could be

Categories : Objective C

Objective-C implementation of Ruby "chunk"
Why not use a single NSCountedSet to store all the keys and the count of each one? NSArray *sourceArray = @[ @1, @3, @5, @7, @9, @8, @5, @3, @2, @4, @3, @6 ]; NSCountedSet *countedSet = [[NSCountedSet alloc] initWithArray:sourceArray]; NSArray* sortedKeys = [[countedSet allObjects] sortedArrayUsingSelector:@selector(compare:)]; for (NSNumber *key in sortedKeys) { NSUInteger count = [countedSet countForObject:key]; NSLog(@"Key: %@ count: %ld", key, (unsigned long)count); }

Categories : Objective C

Calling objective-c selector methods through FFI in Ruby
In short, you can't. At least not without a slew of hoop jumping. attach_function does what it says; it binds a C function into the Ruby runtime. beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo: is not a C function; it is a selector. What you really want to bind is the implementation of that selector. But not really. What you'd really want to bind is objc_msgSend with a type signature that includes all the arguments to that method. And you'll also need to attach sel_getUid. Oh, and you'll need to attach objc_lookUpClass Then you would do something like (pseudo code): ... attach objc_msgSend to msgSend with no arguments and object return type ... alert = msgSend(msgSend(msgSend(lookupClass("NSAlert"),getUid("alloc")), getUid("init")), getUid("auto

Categories : Objective C

Need help converting SQL query to Ruby.
Try: Bidding.where('listing_id = :listing_id', listing_id: 1).maximum(:bid_amount) Update: To follow up on your comment: since you say you are passing in params[:id], it's best to convert that parameter to integer so that unwanted values don't go to the database. For e.g. Bidding.where('listing_id = :listing_id', listing_id: params[:id].to_i).maximum(:bid_amount)

Categories : SQL

Converting regex from ruby to PHP
The problem lies with your backslashes. I managed to get it to compile after removing all backslashes. Then, I replaced all double slashes with 4 of them, and preg_match_all() was able to compile the regex too. const PAIR = '/("[^"\\]*(?:\\.[^"\\]*)*"|[^s=,][^s=,\\]*(?:\\.[^s=,\\]*|=[^,>])*)s*=>s*("[^"\\]*(?:\\.[^"\\]*)*"|[^s=,][^s=,\\]*(?:\\.[^s=,\\]*|=[^,>])*)/'; You might have to edit it to get the exact regex you want. You had the compilation error because \ was fed to the regex engine as , which escaped the immediate square brackets. To encode a literal backslash, you need to use \\ - once for the string, and once for the regex engine. string '\\' --becomes--> regex \ --becomes--> literal Ruby doesn't have this problem because its regex syntax is separate from

Categories : PHP

XML Parsing and converting to hash - Ruby
Here is one way of doing it (off the top of my head, based on your initial solution): entities = doc.xpath("/entity_list/entity").map do |entity| { :id => entity.at_xpath("id").content.to_i, :first_name => entity.at_xpath("first_name").content, :last_name => entity.at_xpath("last_name").content, :preferred_email => entity.at_xpath("contact_list/contact[contains(type,'Email') and contains(preferred, '1')]/value").content, :manager => entity.at_xpath("manager").content } end EDIT To rescue from missing nodes you could use ActiveSupport's try method, or just tack a rescue nil onto the end of each line, e.g.: :first_name => (entity.at_xpath("first_name").content rescue nil), But it would be better to use a helper method, something like: def get

Categories : Ruby

Differences between Keyword Arguments in Ruby 2.0 and Interleaved method signatures in Objective-C
The key difference between keyword arguments and interleaved arguments is exactly as you've guessed; the keywords are not part of the method name (the selector in Objective-C). Specifically, you can't reorder or drop parts of a Objective-C method's selector because that would be naming a different method. This is also why us Obj-C graybeards bristle whenever someone describes Objective-C methods as having keywords preceding each argument. You might find the question and answers on this particular question relevant. Brad Cox -- one of the inventors of Objective-C -- answered.

Categories : Objective C

Converting NArray to Magick::Image in Ruby
Here is some code I used to do this for greyscale only, and seems relatively quick: module Convert PX_SCALE = ( 2 ** Magick::QuantumDepth ).to_f # Converts 2D NArray of floats 0.0->1.0 to Magick::Image greyscale (16-bit depth) def self.narray_to_image na raise( ArgumentError, "Input should be NArray, but it is a #{na.class}") unless na.is_a?(NArray) raise( ArgumentError, "Input should have 2 dimensions, but it has #{na.dim}" ) unless na.dim == 2 width, height = na.shape img = Magick::Image.new( width, height ) { self.depth = 16; self.colorspace = Magick::GRAYColorspace } img.import_pixels(0, 0, width, height, 'I', na.flatten, Magick::DoublePixel ) img end # Converts Magick::Image greyscale to 2D NArray of floats 0.0 -> 1.0 def self.image_to_nar

Categories : Ruby

Converting a decimal to price format in Ruby
The standard answer here is to use sprintf. sprintf("$%2.2f", @product.price) This will format your number with a leading dollar sign, then the number to two decimal places.

Categories : Ruby On Rails

When converting Yaml to a Ruby hash how can I distinguish entries with the same key
If you are able to alter how the Yaml file is generated, or if you are able to preprocess it appropriately, you could create a file containing several Yaml documents. It would look something like this: exampleName: user: user version: 1 artifact: example1 order: 1 --- exampleName: user: user version: 1 artifact: example2 order: 4 --- aName: user: user2 version: 12 artifact: example3 order: 3 Note how each document is separated from the others with ---. You can now parse this using YAML.load_stream, which will give you an array of hashes: YAML.load_stream File.read('./your_yaml_file.yaml') The result will be: [{"exampleName"=> {"user"=>"user", "version"=>1, "artifact"=>"example1", "order"=>1}}, {"exampleName"=> {"user"=>"user", "ve

Categories : Ruby

Are there languages which compile to Objective-C or are binary compatible with Objective-C -> Coffeescript for Objective-C
While the primary way to use eero is to have it compile to native code, it does support source-to-source translation as well (from eero to standard Objective-C/C++). Please see https://github.com/eerolanguage/eero/wiki/Translator for more details. It really needs to be documented in a more obvious place...

Categories : IOS

Objective-C Run Time System
The runtime system sounds like it could be a daemon or something that runs all the time doing runtime-y stuff. It isn't; it is simply a set of utility routines that are linked into your application that the compiler generates calls to to implement things like introspection, class realization, and, most commonly used, method calling. Every Objective-C application will have its own runtime in that every application runs in its own isolated memory space and cannot touch other application's memory. In other words, the Objective-C runtime is entirely passive. It does nothing unless some code is executed that calls it (the one exception being when ObjC is running in a GC'd environment as the GC thread(s) will collude with the runtime to clean up memory). Most high level languages have a ru

Categories : Objective C

Compare time in objective c
Convert NSString to NSDate, compare timeIntervals: NSDateFormatter *df = [[NSDateFormatter alloc]init]; [df setDateFormat:@"HH:mm:ss"]; NSDate *CTDate = [df dateFromString:CT]; NSDate *startDate = [df dateFromString:startTime]; NSTimeInterval CTInterval = [CTDate timeIntervalSince1970]; NSTimeInterval startInterval = [startDate timeIntervalSince1970]; NSTimeInterval deltaInterval = startInterval - CTInterval; if(deltaInterval < 0){ //Ascending (CT < startTime) } else if(deltaInterval > 0){ //Descending (CT > startTime) } else{ //Some (CT = startTime) }

Categories : Objective C

Ruby on Rails: Converting audio in background and uploading using paperclip?
delayed_job is a widely used solution for applications where you need something intensive to be done, but not right away. I would recommend it unless your user is going to need the modified file immediately. Alternatives: Resque Sidekiq Navvy Queue Classic For more options, see: https://www.ruby-toolbox.com/categories/Background_Jobs

Categories : Ruby On Rails

Is any data lost when converting a Ruby float in scientific notation to an integer?
On the contrary, (deterministic but meaningless) data is added (as you demonstrated in your code sample). You're not losing any information. But it's not the same value. Your float has a precision of about 17 decimal digits, your int suddenly has a precision of 51 digits. This has to do with Floating Point Arithmetic: Issues and Limitations. That "precision" arises as the result of the binary representation of a decimal floating point value, which leads to the "invention" of a series of digits in your integer. Consider the following (in Python, which follows the same rules, as will probably all programming languages that feature arbitrarily long integers): >>> a = int(1.5815450433041317e+51) >>> a 1581545043304131697954259018410479150921451567054848 >>> b = a

Categories : Ruby

C++ character encoding when converting from string to const char* for Ruby FFI interface
The value returned by c_str() is destroyed as soon as the std::string goes out of scope. If you intend to pass this value to your script you should allocate memory and copy the string into your newly allocated space. See this example: http://www.cplusplus.com/reference/string/string/c_str/ You should also ensure the ruby script will correctly release memory. I think this is what is explained there: https://github.com/ffi/ffi/wiki/Examples. Example with a struct passed to Ruby from C: https://github.com/ffi/ffi/wiki/Examples#-structs

Categories : C++

textField validation on real time in objective-C
you can use this: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { // Valida el patron que se introduce en el campo de texto if (![self validateString:string withPattern:@"^([A-Z0-9.@-_ ])*$"]) return NO; return YES; } in the withPattern parameter insert your regex expression, and then here it is the method which does all the magic: - (BOOL)validateString:(NSString *)string withPattern:(NSString *)pattern { NSError *error = nil; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:&error]; NSAssert(regex, @"Unable to create regular expression"); NSRange textRange = NSMakeRan

Categories : IOS

Objective-c how to get a date with no time components at GMT timezone?
Best thing to do is follow the SDK convention of doing everything in GMT, only converting to local timezones for the user to see. Your code does math on hours and minutes, which leaves open the chance for errors on edge cases. It's better let the sdk do the math. To get the zero hour of a given date, try something like this... NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:(NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:startDate]; NSDate *justTheDay = [calendar dateFromComponents:components];

Categories : Iphone

PHP TIME converting?
You could have got the answer to that with a little bit of searching. But here you go: echo date('m/d/Y h:m', 1375202508); // 07/30/2013 10:07 -- 12-hour format echo date('m/d/Y H:m', 1375202508); // 07/30/2013 22:07 -- 24-hour format See the documentation for more options: http://php.net/manual/en/function.date.php

Categories : PHP

Converting time 1am to 1pm in matlab
It looks like your import from Excel has brought it in as a serial Date number I think you need to have a look at how your importing dates from Excel. It can be problematic due to the differing ways Excel and Matlab handle dates. Have a look at this link I expect your also going to need to use the DateStr function For example converting the time 01:00 pm in it's 12-hour format to a 24-hour format. datestr('01:00 PM','HH:MM') Edit: Or alternativley Look at addtodate(). addtodate(0.0417,12,'hour') This should add 12 hours to your 01:00 making it 13:00.

Categories : Matlab

converting a time to a different timezone with php
You can use date_default_timezone_set function to change loacal time zone Example date_default_timezone_set('Europe/Paris');

Categories : PHP

Ruby Time object converted from float doesn't equal to orignial Time object
IEEE 754 double (which is returned by to_f) is not accurate enough to represent the exact time. t1 = Time.now f1 = t1.to_f t2 = Time.at(f1) # they look the same t1.inspect #=> '2013-09-09 23:46:08 +0200' t2.inspect #=> '2013-09-09 23:46:08 +0200' # but double does not have enough precision to be accurate to the nanosecond t1.nsec #=> 827938306 t2.nsec #=> 827938318 # ^^ # so they are different t1 == t2 #=> false Do the following, to preserve the exact time: t1 = Time.now r1 = t1.to_r # value of time as a rational number t2 = Time.at(r1) t1 == t2 #=> true Citation from Time.to_r: This methods is intended to be used to get an accurate value representing the nanoseconds since the Epoch. You can use this method to convert time to another Epoc

Categories : Ruby

how to avoid system modify time stam, NSDate, objective c
I personally do not know objective C but I do know the point of the problem. I'll try to guess along with the syntax. When you receive 2013-07-08 16:45:03Z the Z means UTC, or GMT+/-0000. You are parsing it as a local timezone, or GMT-0400. You then reemit it as reconverted into UTC with a 4 hour overcompensation. To fix this, change: NSTimeZone *destinationTimeZone = [NSTimeZone systemTimeZone]; to NSTimeZone *destinationTimeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; Honestly, I'm not sure if you need to do any wrapping for the 0 to act as an NSInteger but that's what you need. You may have been intermittently missing this bug as a failure to determine time would have fallen back to the desired effect. Out of curiosity, could someone comment as to whether my code is at l

Categories : Iphone

converting string to time for comparison
Why do you convert the strings when they are perfectly comparable? int main() { std::string str1 = "20110627120000"; std::string str2 = "20110629120000"; std::cout << ((str1 < str2) ? "True" : "False") << std::endl; } Using sscanf with the format having a space in between "%4d%2d%2d %2d%2d%2d" looks plain wrong. Not checking the result of it, is.

Categories : C++

failed when converting date and/or time
Not sure I totally understand the desired output, but if you're forced to hack strings together to generate differently formatted datetime values, this may work. DECLARE @strDate VARCHAR(50) = '3/25/13 10:06:38 AM', @dtDate DATETIME, @DateOnly VARCHAR(255), @TimeOnly VARCHAR(255), @output VARCHAR(255) -- cast to datetime first to verify its a valid date SET @dtDate = CAST(@strDate AS DATETIME) -- parse/cast date and time to seperate variables SET @DateOnly = CONVERT(VARCHAR(255),@dtDate,101) SET @TimeOnly = CONVERT(VARCHAR(255),@dtDate,108) -- duct tape them back together in the desired string format SET @output = @DateOnly + ' ' + @TimeOnly -- outputs '03/25/2013 10:06:38' SELECT @output AS 'NewStringDate'

Categories : Sql Server

Converting Unix time to GMT datetime with php
You can change the time to different timezone. The PHP function is: date_default_timezone_set() More info: http://php.net/manual/en/function.date-default-timezone-set.php

Categories : PHP

Converting Seconds to Time Format
First off you should state your question more clearly. "Converting Seconds to Time Format" Seconds are one way to represent duration, but some kind of reference is needed to make it relevant. A.D., UTC, or a duration. See http://en.wikipedia.org/wiki/ISO_8601 for the win. Try this in a JavaScript Console: d = new Date(1920000) Thu Jan 01 1970 01:32:00 GMT+0100 (Westeuropäische Normalzeit) d.getUTCMinutes() 32 d.getUTCSeconds() 0

Categories : Javascript

Converting from time interval to a statement
Try this one - ALTER TABLE dbo.denouncement_term_day_time ADD time_den_new VARCHAR(20) NULL GO UPDATE dbo.denouncement_term_day_time SET time_den_new = CASE WHEN time_den BETWEEN '6:00:00' AND '11:59:59' THEN 'Morning' WHEN time_den BETWEEN '12:00:00' AND '16:59:59' THEN 'Afternoon' END WHERE time_den BETWEEN '6:00:00' AND '16:59:59' GO ALTER TABLE dbo.denouncement_term_day_time DROP COLUMN time_den GO EXEC sp_rename 'dbo.denouncement_term_day_time.time_den_new', 'time_den', 'COLUMN'

Categories : SQL

Converting a string to a date time in SQL
One potential option is to add a date column to your table and populate that information on load. This way the conversion is all done before you need to query for it. Then, make sure you have an index on that field which the actual query can take advantage of.

Categories : SQL

converting date time format in sql
try this Select cast(CONVERT(varchar(100), @startdate + ' 16:59:59') as date) Or Select cast(CONVERT(varchar(100), @startdate + ' 16:59:59') as datetime)

Categories : Sql Server

Converting Oracle Date and Time
UPDATED A possible solution SELECT CASE WHEN dt - TRUNC(dt) = 0 THEN TO_CHAR(TRUNC(dt) - 1, 'DD-Mon-YYYY') || ' 24:00:00' ELSE TO_CHAR(dt, 'DD-Mon-YYYY HH24:MI:SS') END dt FROM ( SELECT TO_DATE('12-MAY-2013 12:00:00 AM', 'DD-Mon-YYYY HH:MI:SS AM') dt FROM dual ) Output: | DT | ------------------------ | 11-May-2013 24:00:00 | Here is SQLFiddle demo Original answer Try SELECT TO_CHAR(TO_DATE('12-MAY-2013 12:00:00 AM', 'DD-Mon-YYYY HH:MI:SS AM'), 'DD-Mon-YYYY HH24:MI:SS') dt FROM dual Here is SQLFiddle demo

Categories : SQL

Converting Date time format in Java
You mean like this one: import java.util.Date; import java.text.SimpleDateFormat; public class DateFormat{ public static void main(String[] args){ Date date=new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); String yourDate=sdf.format(date); System.out.println(yourDate); } }

Categories : Java

option to display the time in PST by converting milliseconds
Please check this library, it has lot of functions to display and manupilate date time. http://momentjs.com/ http://momentjs.com/docs/ Also please check following post Moment.js: Format date in a specific timezone If you dont want to use external lib, see the following article http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329

Categories : Javascript

Converting a MySQL database row time timezone
The following solution works perfectly: $oldDate = date('l F j Y H:i:s', $link['date']); $date = new DateTime($oldDate, new DateTimeZone('Europe/London')); $date->setTimezone(new DateTimeZone('UTC')); echo $date->format('r');

Categories : PHP

Converting timeuuid to date-time in phpcassa
You can use the $time attribute of phpcassaUUID objects to get a unix timestamp, like so: $timeuuid = UUID::uuid1(); echo "timestamp: $timeuuid->time"; From there it's easy to make other date and time objects.

Categories : Cassandra



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.