code-snippets

Handy F# snippets [closed]

╄→гoц情女王★ 提交于 2019-11-26 16:51:53
There are already two questions about F#/functional snippets. However what I'm looking for here are useful snippets, little 'helper' functions that are reusable. Or obscure but nifty patterns that you can never quite remember. Something like: open System.IO let rec visitor dir filter= seq { yield! Directory.GetFiles(dir, filter) for subdir in Directory.GetDirectories(dir) do yield! visitor subdir filter} I'd like to make this a kind of handy reference page. As such there will be no right answer, but hopefully lots of good ones. EDIT Tomas Petricek has created a site specifically for F#

Shortcut to create properties in Visual Studio?

孤人 提交于 2019-11-26 14:58:51
问题 I have seen some people creating properties in C# really fast, but how did they do it? What shortcuts are available in Visual Studio (currently using Visual Studio 2010) to create properties? I am using C#. For example, public string myString {get;set;} 回答1: You could type "prop" and then press tab twice. That will generate the following. public TYPE Type { get; set; } Then you change "TYPE" and "Type": public string myString {get; set;} You can also get the full property typing "propfull"

Storing code snippets in eclipse

六眼飞鱼酱① 提交于 2019-11-26 10:09:39
问题 I\'m a recent semi-convert to Eclipse after 20 years of using vi and gvim. One of the things I miss about gvim is that I could cut a bunch of different snippets of code into named buffers, and paste them at will when doing something like repeating a common idiom. For instance I\'d have it so \"ap would paste DatabaseHandle handle = null; try { handle = DatabaseConnectionPool.newHandle(); and then \"bp would paste handle.commit(); } finally { handle.rollback(); DatabaseConnectionPool

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in

最后都变了- 提交于 2019-11-26 07:48:31
问题 I\'m working with PHP PDO and I have the following problem: Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /var/www/site/classes/enterprise.php on line 63 Here is my code: public function getCompaniesByCity(City $city, $options = null) { $database = Connection::getConnection(); if(empty($options)) { $statement = $database->prepare(\"SELECT * FROM `empresas` WHERE `empresas`.`cidades_codigo` = ?\");

Reusable library to get human readable version of file size?

白昼怎懂夜的黑 提交于 2019-11-26 06:04:22
问题 There are various snippets on the web that would give you a function to return human readable size from bytes size: >>> human_readable(2048) \'2 kilobytes\' >>> But is there a Python library that provides this? 回答1: Addressing the above "too small a task to require a library" issue by a straightforward implementation: def sizeof_fmt(num, suffix='B'): for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']: if abs(num) < 1024.0: return "%3.1f%s%s" % (num, unit, suffix) num /= 1024.0 return "%.1f%s

How to detect if JavaScript is disabled?

三世轮回 提交于 2019-11-26 01:18:12
问题 There was a post this morning asking about how many people disable JavaScript. Then I began to wonder what techniques might be used to determine if the user has it disabled. Does anyone know of some short/simple ways to detect if JavaScript is disabled? My intention is to give a warning that the site is not able to function properly without the browser having JS enabled. Eventually I would want to redirect them to content that is able to work in the absence of JS, but I need this detection as

Choose File Dialog [closed]

喜夏-厌秋 提交于 2019-11-26 00:56:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Does anyone know of a complete choose file dialog? Maybe one where you can filter out all files except for ones with specific extensions? I have not found anything lightweight enough to implement easily into one of my projects. The only other option seems to be using OI FileManager\'s open intents, but that