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
| # Does "git push origin <current branch>" | |
| function push { | |
| git push origin $(git branch | grep "\*" | sed "s/\*\s//g") | |
| } | |
| # Does "git pull origin <current branch>" | |
| function pull { | |
| git pull origin $(git branch | grep "\*" | sed "s/\*\s//g") | |
| } |
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
| zpad = (s='', n=0)-> | |
| s += '' | |
| while s.length < n | |
| s = '0' + s | |
| s | |
| #Javascript date formatting. Supports a subset of Python's formats for datetime.strptime | |
| #http://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior | |
| months = 'January,February,March,April,May,June,July,August,September,October,November,December'.split(',') | |
| months_abbr = (m.substr(0,3) for m in months) |
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
| ### | |
| Python style "import" for coffeescript (this does not load resources, it only manipulates namespaces): | |
| # Where you would do this: | |
| from module.package import * | |
| p = PackageClass() | |
| # Do this, where module is the already global name, such as APP.MODULE | |
| eval importAllFrom 'module.package' | |
| p = PackageClass() |
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
| # zpad(s, n) pads a string <s> with zeros in order to make it at least length <n> | |
| zpad = (s='', n=0)-> | |
| s += '' # cast to string | |
| while s.length < n | |
| s = '0' + s | |
| s | |
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
| $.fn.serializeObject = -> | |
| o = {} | |
| a = @serializeArray() | |
| $.each a, -> | |
| if o[@name] | |
| o[@name] = [o[@name]] unless o[@name].push | |
| o[@name].push @value or "" | |
| else | |
| o[@name] = @value or "" |
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
| # Object.beget - returns a new object based on a prototype and extra attributes | |
| # @param {object} o - the object to use as a prototype | |
| # @param {object} moar - extra attributes to apply to the object. | |
| # @param {function} o.init - optional constructor function. | |
| Object.beget = (o, moar = {})-> | |
| F = moar.init ? new Function() # now F can be used as a constructor. | |
| F.prototype = o # All new objects F creates will be based on o. | |
| child = new F() | |
| for own k,v of moar | |
| child[k] = v |
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 sys | |
| import re | |
| def num_endings(istr, ending): | |
| n = 0 | |
| for i in reversed(istr): | |
| if i == ending: | |
| n += 1 | |
| else: |
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
| <!--Place the code for your plugin wherever you want the plugin to appear on your page. --> | |
| <div class="fb-like" data-href="http://developers.facebook.com/docs/reference/plugins/like" data-send="true" data-width="450" data-show-faces="true"></div> | |
| <!-- Include the JavaScript SDK on your page once, ideally right after the opening <body> tag. --> | |
| <div id="fb-root"></div> | |
| <script>(function(d, s, id) { | |
| var js, fjs = d.getElementsByTagName(s)[0]; | |
| if (d.getElementById(id)) return; | |
| js = d.createElement(s); js.id = id; | |
| js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; |
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
| # string.format | |
| # Simply map named variables in a string to attributes of an object. | |
| # ie) | |
| # | |
| # ''' I am a {fruit} '''.format {fruit: 'banana'} | |
| # >>> I am a banana. | |
| String::format = (str, dict)-> | |
| str.replace /\{([^\}]+)\}/g, (match, $1)-> | |
| dict[$1] or '' |