truncate

Shorten URL for display with beginning and end preserved (Firebug 'Net' panel style)

跟風遠走 提交于 2019-12-11 06:16:56
问题 I would like to display a URL in a table while restricting it to a specific length. Being a URL, it would be nice to preserve the most meaningful parts which tend to be the beginning and end. This functionality can be seen when viewing long URLs in the Firebug 'Net' panel. 回答1: This is a quick and dirty solution but it has been working well for me so far and can be easily updated to any individual preferences. It's broken into two functions for readability and reuse. This function makes use

PostgreSQL - Truncating A Date Within Age Function

跟風遠走 提交于 2019-12-11 04:50:29
问题 I have the following query: SELECT usersid as user, (age(creationtime)) as account_days FROM users which outputs users (an integer) and account_days which uses the timestamp to output the age (i.e. 58 days, 2:31:31.387746). I want the output to just say 58, instead of 58 days, 2:31:31.387746. How would I go about this? I attempted SELECT usersid as user, EXTRACT(day FROM(age(creationtime))) as account_days FROM users but it changes the output to a number that doesn't tie out. Im using version

How to select top N elements from a JavaPairRDD ? -Apache Spark

让人想犯罪 __ 提交于 2019-12-11 03:13:37
问题 I have obtained a key/value pair, and sorted it into a new JavaPairRDD Now, I need to select the top 5 elements from it, that is, to obtain a new JavaPairRDD with those top 5 elements in it. How would I do that ? Is there a simpler way than using the flatMap, since it seems like the unnecessary extra work ? Thanks! 回答1: Assuming you don't care about order, you can use RDD.take(5) to get the first 5 elements in an RDD. 回答2: To get the top (or bottom) items (and answer the question you asked),

Truncate dictionary list values

旧城冷巷雨未停 提交于 2019-12-10 23:59:29
问题 I'm trying to find the keys for the matching values in a dictionary. But to get any kind of valid match I need to truncate the values in the lists. I want to truncate down the the tenths spot (e.g. "2.21" to "2.2"). dict1 = {'red':[1.98,2.95,3.83],'blue':[2.21,3.23,4.2333],'orange':[3.14,4.1,5.22]} dict2 = {'green':[3.11,4.12,5.2],'yellow':[2.2,3.2,4.2],'red':[5,2,6]} matches = [] for key1 in dict1: for key2 in dict2: if dict1[key1] == dict2[key2]: matches.append((key1, key2)) print(matches)

Truncate or Drop and Create Table

一笑奈何 提交于 2019-12-10 12:29:18
问题 I have this table in a SQL Server 2008 R2 instance which I have a scheduled process that runs nightly against it. The table can have upward to 500K records in it at any one time. After processing this table I need to remove all rows from it so I am wondering which of the following methods would produce the least overhead (ie Excessive Transaction Log entries): Truncate Table Drop and recreate the table Deleting the contents of the table is out due to time and extra Transaction log entries it

Python pandas, how to truncate DatetimeIndex and fill missing data only in certain interval

冷暖自知 提交于 2019-12-09 06:40:28
2012-10-08 07:12:22 0.0 0 0 2315.6 0 0.0 0 2012-10-08 09:14:00 2306.4 20 326586240 2306.4 472 2306.8 4 2012-10-08 09:15:00 2306.8 34 249805440 2306.8 361 2308.0 26 2012-10-08 09:15:01 2308.0 1 53309040 2307.4 77 2308.6 9 2012-10-08 09:15:01.500000 2308.2 1 124630140 2307.0 180 2308.4 1 2012-10-08 09:15:02 2307.0 5 85846260 2308.2 124 2308.0 9 2012-10-08 09:15:02.500000 2307.0 3 128073540 2307.0 185 2307.6 11 ...... 2012-10-09 07:19:30 0.0 0 0 2276.6 0 0.0 0 2012-10-09 09:14:00 2283.2 80 98634240 2283.2 144 2283.4 1 2012-10-09 09:15:00 2285.2 18 126814260 2285.2 185 2285.6 3 2012-10-09 09:15:01

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

此生再无相见时 提交于 2019-12-09 05:00:44
问题 This question already has answers here : JodaTime equivalent of DateUtils.truncate() (4 answers) Closed 4 years ago . 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? 回答1: 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

RODBC and Microsoft SQL Server: Truncating Long Character Strings

左心房为你撑大大i 提交于 2019-12-08 19:39:50
问题 I am trying to query a variable from a Microsoft SQL Server database using R/RODBC. RODBC is truncating the character string at 8000 characters. Original code: truncates at 255 characters (as per RODBC documentation) library(RODBC) con_string <- odbcConnect("DSN") query_string <- "SELECT text_var FROM table_name" dat <- sqlQuery(con_string, query_string, stringsAsFactors=FALSE) Partial solution: modifying query string truncate text after 7999 characters. library(RODBC) con_string <-

Float To Integer Casting?

做~自己de王妃 提交于 2019-12-08 11:37:32
问题 I know that floating point cannot represent every number exactly so some error is bound to happen. But recently I have encountered a problem and I am not getting the explanation right. Please explain me step by step how the conversion affected the output. How did truncating decimal places give me the wrong answer? #include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int x; int y = 0; int n = 0; printf("Enter The Number You Want To Octal Equivalent Of : "); scanf("%d",&x); while

Python pandas, how to truncate DatetimeIndex and fill missing data only in certain interval

血红的双手。 提交于 2019-12-08 07:37:37
问题 2012-10-08 07:12:22 0.0 0 0 2315.6 0 0.0 0 2012-10-08 09:14:00 2306.4 20 326586240 2306.4 472 2306.8 4 2012-10-08 09:15:00 2306.8 34 249805440 2306.8 361 2308.0 26 2012-10-08 09:15:01 2308.0 1 53309040 2307.4 77 2308.6 9 2012-10-08 09:15:01.500000 2308.2 1 124630140 2307.0 180 2308.4 1 2012-10-08 09:15:02 2307.0 5 85846260 2308.2 124 2308.0 9 2012-10-08 09:15:02.500000 2307.0 3 128073540 2307.0 185 2307.6 11 ...... 2012-10-09 07:19:30 0.0 0 0 2276.6 0 0.0 0 2012-10-09 09:14:00 2283.2 80