Most viewed recipes tagged "embedded"http://code.activestate.com/recipes/tags/embedded/views/2014-05-25T16:23:55-07:00ActiveState Code RecipesPython code minifier (Python) 2014-05-25T16:23:55-07:00Dan McDougallhttp://code.activestate.com/recipes/users/4169722/http://code.activestate.com/recipes/576704-python-code-minifier/ <p style="color: grey"> Python recipe 576704 by <a href="/recipes/users/4169722/">Dan McDougall</a> (<a href="/recipes/tags/bz2/">bz2</a>, <a href="/recipes/tags/bzip2/">bzip2</a>, <a href="/recipes/tags/comments/">comments</a>, <a href="/recipes/tags/compression/">compression</a>, <a href="/recipes/tags/docstring/">docstring</a>, <a href="/recipes/tags/embedded/">embedded</a>, <a href="/recipes/tags/gzip/">gzip</a>, <a href="/recipes/tags/minify/">minify</a>, <a href="/recipes/tags/pack/">pack</a>, <a href="/recipes/tags/regex/">regex</a>, <a href="/recipes/tags/zlib/">zlib</a>). Revision 16. </p> <p><strong>Update 05/25/2014:</strong> Pyminifier 2.0 has been released and now lives on Github: <a href="https://github.com/liftoff/pyminifier" rel="nofollow">https://github.com/liftoff/pyminifier</a> (docs are here: <a href="http://liftoff.github.io/pyminifier/" rel="nofollow">http://liftoff.github.io/pyminifier/</a>). The code below is very out-of-date but will be left alone for historical purposes.</p> <p>Python Minifier: Reduces the size of Python code for use on embedded platforms. Performs the following:</p> <ol> <li>Removes docstrings.</li> <li>Removes comments.</li> <li>Removes blank lines.</li> <li>Minimizes code indentation.</li> <li>Joins multiline pairs of parentheses, braces, and brackets (and removes extraneous whitespace within).</li> <li>Preserves shebangs and encoding info (e.g. "# -<em>- coding: utf-8 -</em>-")</li> <li><strong>NEW:</strong> Optionally, produces a bzip2 or gzip-compressed self-extracting python script containing the minified source for ultimate minification.</li> </ol> <p><strong>Update 09/23/2010:</strong> Version 1.4.1: Fixed an indentation bug when operators such as @ and open parens started a line.</p> <p><strong>Update 09/18/2010:</strong> Version 1.4:</p> <ul> <li>Added some command line options to save the result to an output file.</li> <li>Added the ability to save the result as a bzip2 or gzip-compressed self-extracting python script (which is kinda neat--try it!).</li> <li>Updated some of the docstrings to provide more examples of what each function does.</li> </ul> <p><strong>Update 06/02/2010:</strong> Version 1.3: Rewrote several functions to use Python's built-in tokenizer module (which I just discovered despite being in Python since version 2.2). This negated the requirement for pyparsing and improved performance by an order of magnitude. It also fixed some pretty serious bugs with dedent() and reduce_operators().</p> <p>PLEASE POST A COMMENT IF YOU ENCOUNTER A BUG!</p> Using SQLite as an embedded database with C# instantly (Text) 2010-12-15T01:24:06-08:00Stephen Akikihttp://code.activestate.com/recipes/users/4172143/http://code.activestate.com/recipes/577500-using-sqlite-as-an-embedded-database-with-c-instan/ <p style="color: grey"> Text recipe 577500 by <a href="/recipes/users/4172143/">Stephen Akiki</a> (<a href="/recipes/tags/akiscode/">akiscode</a>, <a href="/recipes/tags/csharp/">csharp</a>, <a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/embedded/">embedded</a>, <a href="/recipes/tags/sqlite/">sqlite</a>). </p> <p><a href="http://akiscode.com/articles/sqlite-csharp.shtml" rel="nofollow">http://akiscode.com/articles/sqlite-csharp.shtml</a></p> <p>There are a few libaries that every programmer loves and knows because they either:</p> <ul> <li>Saves you a ton of time coding</li> <li>Does something that you don't know how to do yourself</li> </ul> <p>Examples include cURL, SQLite, or even the .NET library itself. Many of us have to create CRUD (Create, Read, Update, Delete) projects on a semi-regular routine. SQLite is nice in the fact that it handles all the CRUD-y stuff (bad pun I know) in a simple, small and standalone package. But because SQLite is so nice to use (when compared to say XML), the Gods have cursed SQLite to cause many headaches if you are a new to it on C# to balance the world karma (or something like that). Also note that i'm not going to explain what any of the code does as its pretty self explanatory. Anyway, here is a complete example on how to setup an embedded SQLite database, insert some data into it, and then update a listview with only certain columns from the database:</p> <p><strong>The Fun Stuff</strong></p> <ol> <li><p><em>*NOTE: I've made a demo project that you can download <a href="http://akiscode.com/articles/Akiscode-SQLiteTest.zip">here</a>. It includes the DLLs and everything that i've talked about below. *</em></p></li> <li><p>Download the setup from <a href="http://sqlite.phxsoftware.com/">these guys</a> and install it.</p></li> <li><p>Start a new Project in Visual C# Studio (I'm using version 2010 Express). Make it a Windows Forms Application. Save it anywhere. For this example, I will save it on the Desktop and call the project "Akiscode-SQLiteTest. At the time I was doing this, the SQLite dll only worked with a program targeted at .NET version 3.5. To learn how to change that go <a href="http://msdn.microsoft.com/en-us/library/bb772098(v=vs.90).aspx">here</a>.</p></li> <li><p>Go to the Solutions Explorer on the top right of your VC setup. Right click references and select "Add Reference". Go to the ".NET" tab and find the entry named "System.Data.SQLite". Not "System.Data.Sql", not "System.Data.SqlXml", NOT "MySql.Data". Just find "System.Data.SQLite". If you can't find it, sort the list by name. If you still can't find it, restart VC and try this process again. Still can't find it? Run the installer and do it all over again. Still not there? Well I can't really help you, hand in your programming badge on the way out.</p></li> <li><p>Once you added "System.Data.SQLite", right click it and select properties. Set "Copy Local" to true.</p></li> <li><p>Ok type at the top "using "using System.Data.SQLite;" without the quotes.</p></li> <li><p>Go back to the form designer. Add a listview component. In the properties window (bottom right) make sure the property view is set to "Details". Then right click on the listview and add columns. For this example I added two called "First Name" and "Last Name"</p></li> </ol> <p>8.Ok now for some copy and paste coding (my favorite): Double click the form to make a "Form1_Load" function appear and paste the following in it:</p> Serve static web content from within a gzipped tarball to save space using CherryPy (Python) 2009-03-31T18:24:06-07:00Dan McDougallhttp://code.activestate.com/recipes/users/4169722/http://code.activestate.com/recipes/576706-serve-static-web-content-from-within-a-gzipped-tar/ <p style="color: grey"> Python recipe 576706 by <a href="/recipes/users/4169722/">Dan McDougall</a> (<a href="/recipes/tags/cherrypy/">cherrypy</a>, <a href="/recipes/tags/compression/">compression</a>, <a href="/recipes/tags/embedded/">embedded</a>, <a href="/recipes/tags/gzip/">gzip</a>, <a href="/recipes/tags/html/">html</a>, <a href="/recipes/tags/http/">http</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/routes/">routes</a>, <a href="/recipes/tags/web/">web</a>, <a href="/recipes/tags/web_server/">web_server</a>). </p> <p>This code lets you store all of your static website content inside a gzipped tarball while transparently serving it to HTTP clients on-demand. Perfect for embedded systems where space is limited.</p>