Skip to content

Instantly share code, notes, and snippets.

View timmyomahony's full-sized avatar

Timmy O'Mahony timmyomahony

View GitHub Profile
@timmyomahony
timmyomahony / models.py
Created December 13, 2012 00:14
Automatically generating admin URLs for your objects
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db import models
class AdminURLMixin(object):
def get_admin_url(self):
content_type = ContentType \
.objects \
.get_for_model(self.__class__)
return reverse("admin:%s_%s_change" % (
@timmyomahony
timmyomahony / nginx.conf
Created August 11, 2013 13:31
Digital Ocean 512mb, Debian 7 x64, Default Nginx Configuration.
user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
var single_pair_validator = function(hand){
};
var high_card_validation = function(white_numbered_hand, black_numbered_hand){
for(var i=0; i < white_numbered_hand.length; i++){
if(white_numbered_hand[i] > black_numbered_hand[i]){
return "White wins";
}
if(white_numbered_hand[i] < black_numbered_hand[i]){
@timmyomahony
timmyomahony / components.slide-list-item.js
Last active July 18, 2016 11:11
Telling your parents you've rendered
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'li',
classNames: ['slide-list__list__item'],
didInsertElement() {
this._super(...arguments);
this.get('childRendered')();
}
});
@timmyomahony
timmyomahony / javscript-data-structures-and-control-challenge.markdown
Created January 15, 2017 14:00
Javscript data structures and control challenge

Javscript data structures and control challenge

This is from the challenge at the end of the the "javascript data structures and control" section of stream 1

A Pen by Timmy on CodePen.

License.

@timmyomahony
timmyomahony / controllers.application.js
Created April 20, 2017 15:37
Query Params from setupController
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
var UK = d3.locale({
"decimal": ".",
"thousands": ",",
"grouping": [3],
"currency": ["£", ""],
"dateTime": "%a %b %e %X %Y",
"date": "%m/%d/%Y",
"time": "%H:%M:%S",
"periods": ["AM", "PM"],
"days": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
@timmyomahony
timmyomahony / app.py
Last active December 5, 2017 12:43
Getting Flask and MySQL set up
from flask import Flask, jsonify
from flask_mysqldb import MySQL
app = Flask(__name__)
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'testtest1234'
app.config['MYSQL_DB'] = 'test_db'
mysql = MySQL(app)
@timmyomahony
timmyomahony / controller.js
Created February 26, 2018 20:20
Example Angular form
$scope.submitForm = function(isValid) {
if ($scope.userForm.$valid) {
alert('Thank you for registering');
location.reload();
} else {
alert('Error registering');
}
}
@timmyomahony
timmyomahony / components.drag-box.js
Last active April 24, 2018 10:58
Draggable Ember Component
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['drag-box'],
attributeBindings: ['draggable'],
draggable: true,
x: 0,
y: 0,
positionChanged: Ember.observer('x', 'y', function(){
this.$().css({