persistent

Store existing data-type with Yesod's Persistent

吃可爱长大的小学妹 提交于 2019-12-03 12:27:39
All the tutorials and references that I could find about Persistent describe in great detail how Persistent can automatically create a new data-type, schema, migration, etc. out of a single definition in its DSL. However, I couldn't find an explanation on how to get Persistent to handle already existing data-types. An example: Suppose I have an already existing Haskell module for some game logic. It includes a record type for a player. (It's meant to be used through lenses, hence the underscores.) data Player = Player { _name :: String , _points :: Int -- more fields ... } $(makeLenses '

subset() drops attributes on vectors; how to maintain/persist them?

ぐ巨炮叔叔 提交于 2019-12-03 09:08:37
问题 Let's say I have a vector where I've set a few attributes: vec <- sample(50:100,1000, replace=TRUE) attr(vec, "someattr") <- "Hello World" When I subset the vector, the attributes are dropped. For example: tmp.vec <- vec[which(vec > 80)] attributes(tmp.vec) # Now NULL Is there a way to, subset and persist attributes without having to save them to another temporary object? Bonus: Where would one find documentation of this behaviour? 回答1: I would write a method for [ or subset() (depending on

Persistent HttpURLConnections on Android

最后都变了- 提交于 2019-12-03 08:57:12
I've got an issue trying to get the Android application (well, Service, it case it makes any difference) to use persistent HTTP 1.1 connections. The following loop (simplified test case) works through a single TCP session on a desktop JRE, but on an Android device results in the whole socket creation/teardown cycle. while (true) { URL url; try { url = new URL("http://10.0.0.125:8080/SRV?"); URLConnection connection = url.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection) connection; int responseCode = httpConnection.getResponseCode(); } catch (MalformedURLException e) { }

How to get generated ID after I inserted into a new data record in database using Spring JDBCTemplate?

亡梦爱人 提交于 2019-12-03 08:19:26
I got a very common question when I was using Spring JDBCTemplate, I want to get the ID value after I inserted a new data record into database, this ID value will be referred to another related table. I tried the following way to insert it, but I always return 1 rather than its real unique ID. (I use MySQL as the database) public int insert(BasicModel entity) { String insertIntoSql = QueryUtil.getInsertIntoSqlStatement(entity); log.info("SQL Statement for inserting into: " + insertIntoSql); return this.jdbcTemplate.update(insertIntoSql); } JdbcTemplate.update() returns: the number of rows

Correct way to do a “join” in persist with yesod

我只是一个虾纸丫 提交于 2019-12-03 07:45:25
Consider the models: Player name Text nick Text email Text Maybe phone Text Maybe note Textarea Maybe minutes Int Maybe deriving Table name Text game Text pointsHour Int seats Int Maybe description Text Maybe deriving GamingSession start UTCTime end UTCTime Maybe player PlayerId table TableId seat Int Maybe deriving and the function getGamingSessionsR :: Handler RepHtml getGamingSessionsR = do sessions <- runDB $ selectList [GamingSessionEnd ==. Nothing] [Desc GamingSessionTable] defaultLayout $(widgetFile ("opensessions")) how would one go about getting all of the Player names for each of the

Baffled by selectOneMany in Yesod

烈酒焚心 提交于 2019-12-02 03:35:43
问题 Sweet but simple, how do Persistent joins work? Consider the following model: Person number Int numberOfEyes Int firstName FirstnamesId lastName LastnamesId Lastnames lastname String Firstnames firstname String Assuming I only have the number of a Person, how do I retrieve his full name and the number of his eyes? I tried looking through the haskellers.org source but couldn't find any examples of joins. I also checked out the chapter on joins in the yesod book but it only made my eyes spin.

Persistent objects in recursive python functions

本秂侑毒 提交于 2019-12-01 09:06:56
问题 I am trying to write a recursive function that needs to store and modify an object (say a set) as it recurses. Should I use a global name inside the function? Another option is to modify or inherit the class of the parameter of the function so that it can keep this persistent object but I don't find it elegant. I could also use a stack if I would forgo the recursion altogether... Is there a pythonic way of doing this? Could a generator do the trick? 回答1: Just pass through your persistent

Implementing a file based queue

强颜欢笑 提交于 2019-12-01 03:24:00
I have an in memory bounded queue in which multiple threads queue objects. Normally the queue should be emptied by a single reader thread that processes the items in the queue. However, there is a possibility that the queue is filled up. In such a case I would like to persist any additional items on the disk that would be processed by another background reader thread that scans a directory for such files and processes the entries within the files. I am familiar with Active MQ but prefer a more light weight solution. It is ok if the "FIFO" is not strictly followed (since the persisted entries

Showing a common music player in all activities

瘦欲@ 提交于 2019-12-01 00:22:49
I'm working on an app for a band, which consists of several different activities such as an agenda, news section, album section et cetera. Since it's for a band, I would like to play the band's songs in the background. This isn't such a problem, but I would like to show a small music player on the bottom of all activities so users can always stop, skip, or replay a song if they want to. An example of this can be found in the apps of Mobile Roadie, for instance. However I have no idea how to do this. My best guess is creating a music player class with its own layout, and including this at the

Python: Persistent shell variables in subprocess

[亡魂溺海] 提交于 2019-11-30 20:11:00
I'm trying to execute a series of commands using Pythons subprocess module, however I need to set shell variables with export before running them. Of course the shell doesn't seem to be persistent so when I run a command later those shell variables are lost. Is there any way to go about this? I could create a /bin/sh process, but how would I get the exit codes of the commands run under that? subprocess.Popen takes an optional named argument env that's a dictionary to use as the subprocess's environment (what you're describing as "shell variables"). Prepare a dict as you need it (you may start