This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pip install git+https://github.com/carymrobbins/django.git@fix_libgeos_for_mac#egg=django --upgrade |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ActiveRecord::Base | |
| # Performs an insert, update, and/or delete in a single SQL query. Note that | |
| # this will only work with PostgreSQL. | |
| # Params: | |
| # - data: Array of Hash to be upserted. | |
| # - translation: Hash to map keys in data elements to fields in the database. | |
| # - constants: Hash of constants to merge into every data row. | |
| # - field_names: Array of field names to use from data for the upsert. These | |
| # should match your database, not your upsert data. By default | |
| # this will be determined by the translated keys of your first |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # found this from Armin R. on Twitter, what a beautiful gem ;) | |
| import ctypes | |
| from types import DictProxyType, MethodType | |
| def main(): | |
| import datetime | |
| class _(monkey(int)): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.List | |
| type Dict = [(String, String)] | |
| views :: Dict | |
| views = [ ("foo", "select bar") | |
| , ("bar", "select shoe") | |
| , ("shoe", "select none") | |
| , ("cat", "select foo") | |
| , ("dog", "select mouse") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env runghc | |
| import Data.Tuple | |
| import System.Process | |
| main = do | |
| out <- getBash "ls .cabal-sandbox/lib/*" | |
| let packages = lines out | |
| let packageVersions = map (tjoin "==" . splitVersion) packages | |
| putStrLn . unlines $ packageVersions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Check box numbers, can be found in input class. | |
| // e.g. <input class="new-status-21" /> | |
| [21,22,41,55,56,42,54].each(function(n) { | |
| $$('.new-status-' + n).each(function(el) { | |
| el.checked = true; | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.template import Context, Template | |
| print Template("""<script type="text/javascript"> | |
| var foo = 1, | |
| bar = 2, | |
| url = '{% url view_name obj "'+foo+'" "'+bar+'" %}'; | |
| </script>""").render(Context(dict(obj='something'))) | |
| # Output: | |
| <script type="text/javascript"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import connection, models | |
| class MyManager(Manager): | |
| def raw_as_qs(self, raw_query, params=()): | |
| """Execute a raw query and return a QuerySet. The first column in the | |
| result set must be the id field for the model. | |
| :type raw_query: str | unicode | |
| :type params: tuple[T] | dict[str | unicode, T] | |
| :rtype: django.db.models.query.QuerySet | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db.models.fields.related import ReverseSingleRelatedObjectDescriptor | |
| def override_model_field(model, name, column, field): | |
| """Force override a field in a Django Model. | |
| Usage: override_model_field( | |
| MyModel, models.ForeignKey(OtherModel), 'other', 'other_id') | |
| :type model: django.db.models.base.ModelBase | |
| :type name: basestring | |
| :type column: basestring | |
| :type field: django.db.models.fields.Field |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def roundup(x, digits=0): | |
| n = 10**-digits | |
| return round(math.ceil(x / n) * n, digits) |