truncate

How do I create a new Joda DateTime truncated to the last hour? [duplicate]

这一生的挚爱 提交于 2019-12-03 04:17:16
This question already has answers here : JodaTime equivalent of DateUtils.truncate() (4 answers) I am pulling timestamps from a file that I want to create a new DateTime for, but I want to create the DateTime at the floor of the hour (or any Joda Period will do). How Can I do this? Wohoo, found it. Simple like everything in Joda once I traced down the calls. DateTime dt = new DateTime().hourOfDay().roundFloorCopy(); 来源: https://stackoverflow.com/questions/1207957/how-do-i-create-a-new-joda-datetime-truncated-to-the-last-hour

Truncate string with Rails?

拥有回忆 提交于 2019-12-03 04:04:09
问题 I want to truncate a string as follows: input: string = "abcd asfsa sadfsaf safsdaf aaaaaaaaaa aaaaaaaaaa dddddddddddddd" output: string = "abcd asfsa sadfsaf safsdaf aa...ddddd" 回答1: Take a look at truncate, it partially does want you want. If you test whether it got trunctated or not, you could add some of the last part back after the truncated part. truncate("Once upon a time in a world far far away") # => "Once upon a time in a world..." truncate("Once upon a time in a world far far away"

MySQL: Truncate Table within Transaction?

故事扮演 提交于 2019-12-03 03:34:16
问题 I have an InnoDB table that needs to be re-populated every ten minutes within anywhere from 60k to 200k records. Our approach up to this point has been as follows: Turn off Autocommit Truncate the table Perform Select Queries & additional Calculations (using PHP) Insert new records Commit After the Truncate operation is performed though, the data is immediately deleted, and is no longer available from the User Interface. To our users, this has been pretty disconcerting, even though within

How to find out width of truncated UILabel text

倖福魔咒の 提交于 2019-12-03 03:12:19
I have UILabel , which contains dynamic text. Sometimes text is too long to be shown and thus automagically truncated . How do I find out width of the visible part of truncated text? sizeThatFits returns length of untruncated text , so at the moment I can only detect when truncation will be done. Need to know how much is visible, including those three dots. Any tips? Clarification : when text is truncated, it's usually shorter than UILabel width. Robot K is correct. If I was you I'd do the following: UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 24)]; label.text = @

Is it possible to delete bytes from the beginning of a file?

眉间皱痕 提交于 2019-12-03 03:03:39
I know that I can efficiently truncate a file and remove bytes from the end of the file. Is there a corresponding efficient way to truncate files by deleting content from the beginning of the file to a point in the middle of the file? As I read the question you are asking to remove content from a file starting from the beginning of the file. In other words you wish to delete content at the start of the file and shift the remaining content down. This is not possible. You can only truncate a file from the end, not from the beginning. You will need to copy the remaining content into a new file,

Rails truncate helper with link as omit text

流过昼夜 提交于 2019-12-03 02:53:24
I'm quite long description that I want to truncate using truncate helper. So i'm using the: truncate article.description, :length => 200, :omission => ' ...' The problem is that I want to use more as a clickable link so in theory I could use this: truncate article.description, :length => 200, :omission => "... #{link_to('[more]', articles_path(article)}" Omission text is handled as unsafe so it's escaped. I tried to make it html_safe but it didn't work, instead of link [more] my browser is still showing the html for that link. Is there any way to force truncate to print omission link instead

What is the best way to empty a self-referential MySQL table?

别说谁变了你拦得住时间么 提交于 2019-12-03 01:45:26
I have a self-referential MySQL table with a recursive parent_id: CREATE TABLE `recursive` ( `id` int(11) NOT NULL auto_increment, `parent_id` int(11) default NULL, `name` varchar(100) NOT NULL, PRIMARY KEY (`id`), KEY `data_categorysource_parent_id` (`parent_id`), CONSTRAINT `parent_id_refs_id_627b4293` FOREIGN KEY (`parent_id`) REFERENCES `data_categorysource` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 During testing, I want to empty it but TRUNCATE fails: TRUNCATE `recursive` /* SQL Error: Cannot delete or update a parent row: a foreign key constraint fails... I currently have to manually

How to generate a compiler warning/error when object sliced

落花浮王杯 提交于 2019-12-03 00:25:42
I want to know if it is possible to let compiler issue a warning/error for code as following: Note: 1. Yea, it is bad programming style and we should avoid such cases - but we are dealing with legacy code and hope compiler can help identify such cases for us.) 2. I prefer a compiler option (VC++) to disable or enable object slicing, if there is any. class Base{}; class Derived: public Base{}; void Func(Base) { } //void Func(Derived) //{ // //} //main Func(Derived()); Here if I comment out the second function, the first function would be called - and the compiler (both VC++ and Gcc) feels

Truncate table(s) with rails console

旧街凉风 提交于 2019-12-02 21:43:20
I have this testingdatabase which, by now, is stuffed with junk. Now I've done a few Table.destroy_all commands in the rails console which deletes all records and dependencies which is awesome. However; I'd like to truncate everything so the ID's etc. start at 1 again. Is there any way in Rails 3? Ravi Sankar Raju The accepted answer only works if you need to recreate the whole database. To drop a single table (with the callbacks) and to get the IDs to start from 1: Model.destroy_all # Only necessary if you want to trigger callbacks. ActiveRecord::Base.connection.execute("TRUNCATE #{table_name

Truncate string with Rails?

若如初见. 提交于 2019-12-02 17:23:24
I want to truncate a string as follows: input: string = "abcd asfsa sadfsaf safsdaf aaaaaaaaaa aaaaaaaaaa dddddddddddddd" output: string = "abcd asfsa sadfsaf safsdaf aa...ddddd" Veger Take a look at truncate , it partially does want you want. If you test whether it got trunctated or not, you could add some of the last part back after the truncated part. truncate("Once upon a time in a world far far away") # => "Once upon a time in a world..." truncate("Once upon a time in a world far far away", :length => 17) # => "Once upon a ti..." truncate("Once upon a time in a world far far away",