Skip to content

Instantly share code, notes, and snippets.

View jorendorff's full-sized avatar

Jason Orendorff jorendorff

View GitHub Profile

Good-bye constructor functions?

tl;dr

Constructor function were workaround to specify constructor for a class without class. Now, having class nothing presribes the class being equivalent to its constructor. It always brought confusion and now with constructor empowered, it brings two-space problem. The class keyword can return plain objects, which have [[Construct]] calling the constructor of the class.

Problems

@jorendorff
jorendorff / post.rb
Created December 19, 2012 00:58 — forked from sam452/post.rb
require 'video_title_validator'
class Post < ActiveRecord::Base
attr_accessible :body, :title, :image, :video_title, :video_url
validates :video_url, :presence => true, :if => :video_title_present?
def video_title_present?
puts "YES IT IS BEING CALLED, FINALLY"
!self.video_title.blank?
python shell.py
python <<END
from glu import db
db.create_all()
END
@jorendorff
jorendorff / gist:4224908
Created December 6, 2012 14:43 — forked from slevithan/gist:4222600
Thoughts on use of template strings with XRegExp and ES6

When browsers implement ES6 template strings, add tags XRegExp.r (regex as raw string) and XRegExp.rx (regex with implicit free-spacing, as raw string). Don't need tag XRegExp.raw (raw string), because you should be able to use, e.g., XRegExp(String.raw\w). Don't need to support flags /gy (which XRegExp doesn't allow in mode modifiers) with XRegExp.r/rx, since XRegExp methods provide alternate mechanisms for /gy (scope 'all', the sticky option, lack of need for lastIndex updating, and the XRegExp.globalize method if you really need it). All other flags (e.g., /im and custom flags /snxA) can be applied via a leading mode modifier (e.g., XRegExp.r(?s).).

If the above sounds confusing, keep in mind that you can simply maintain the status quo but still gain the benefits of raw multiline template strings (no more double escaping!) via, e.g.,

@jorendorff
jorendorff / gist:2662282
Created May 11, 2012 20:40 — forked from anonymous/gist:2661058
Ziggurat for Firefox
// This is the code that goes with this screencast: https://www.youtube.com/watch?v=mT-6IQB4vi4
var win = gBrowser.selectedBrowser.contentWindow;
var doc = win.document;
var output = doc.createElement("div");
output.id = "output";
doc.body.appendChild(output);
var style = doc.createElement("style");
style.innerHTML = "div#output { margin-top: 10em; white-space: pre; } div#output span { padding: 0.6em; margin: 0 0.6em; border: 1px solid rgba(0, 0, 0, 0.8); border-radius: 0.2em; box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.4); position: relative; bottom: 1em; background-color: #ff5454; } div#output span > span { background-color: #ffa054; } div#output span > span > span { background-color: #ffff54; } div#output span > span > span > span { background-color: #8cd446; } div#output span > span > span > span > span { background-color: #45d2b0; } div#output span > span > span > span > span > span { background-color: #438ccb; } div#output span > span > span > span > span > span > span { background-color: #8c3fc0; } div#o