Skip to content

Instantly share code, notes, and snippets.

View ryanmcdermott's full-sized avatar
🐢
I may be slow to respond.

Ryan McDermott ryanmcdermott

🐢
I may be slow to respond.
View GitHub Profile
@ryanmcdermott
ryanmcdermott / javascript_new.js
Last active March 15, 2019 04:30
How does JavaScript `new` keyword work?
// _new simulates how `new` keyword works in JS
function _new(func, args) {
let obj = {};
Object.setPrototypeOf(obj, func.prototype);
func.apply(obj, args);
return obj;
}
function Point(x, y) {
this.x = x;
@ryanmcdermott
ryanmcdermott / gist:befb5007d2593c05fb5c
Last active August 29, 2015 14:22
Rotate page slightly and annoyingly
$('body').css('transform', 'rotate(2deg)')
@ryanmcdermott
ryanmcdermott / gist:37264edf045abb595d1a
Created September 6, 2014 20:53
List Comprehension in UnderscoreJS
_.mixin({
listc: function(list, filter, map) {
return _.map(_.filter(list, filter), map)
}
});
/**
* Example:
* var list = [1,2,3,4,5];
* var filter = function (num){ return num < 4; };
@ryanmcdermott
ryanmcdermott / calculategrade.py
Created August 13, 2013 03:01
Final Grade Calculator -- What do you need to score on your final to achieve your desired grade?
def calculate_grade():
current = int(raw_input("Current grade:"))
desired = int(raw_input("Grade desired:"))
percent = float(raw_input("Final's % of Overall Grade:"))
other_percent = 1 - (float(percent / 100))
alg = desired - float((current * other_percent))
grade_needed = round(float(alg / percent) * 100)
print "The grade you need on your final to get your desired grade is " + str(grade_needed)
@ryanmcdermott
ryanmcdermott / Email Login With Django
Created August 6, 2013 23:31
Look up the username associated with a particular email in Django
"""
Look up the username associated with a particular email --
Note Django doesn't seem to create the email field with the UNIQUE attribute.
If that is set to UNIQUE it appears that this is a nice workaround and
very simple solution instead of changing db setup.
Any security problems that you Githubbers and committers see in this?
"""
def login_email(request):
try: