Skip to content

Instantly share code, notes, and snippets.

View RickEyre's full-sized avatar
💭
👑 the crown is in the code base

Rick Eyre RickEyre

💭
👑 the crown is in the code base
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title>Blah</title>
</head>
<body>
<header>
<nav>
<ul>
<li>My</li> <!-- A screenreader would land here first !-->
def longer_country(country1, country2):
return longer(get_capital(country1), get_capital(country2));
# Let's say we have a function:
def say_hello():
print("hello")
# Consider:
pointer = say_hello # the variable 'pointer' now has the function say_hello assigned to it
pointer() # this will print 'hello'
say_hello() # this will also print hello
People.build({
name: 'Whatever',
profile: Profile.build({ /* my-values */ })
}).create({
include: [Profile]
})
@RickEyre
RickEyre / handler.js
Created March 22, 2016 15:35
Error Handler
server.use((error, req, res, next) => {
console.log(error.stack);
next(error);
});
@RickEyre
RickEyre / pubsub.js
Last active August 29, 2015 14:16
Simple Pub Sub
var events = {}
function publish(e, message) {
var subscribers = events[e];
subscribers.map(function(sub) {
sub(message);
});
}
function on(e, cb) {
@RickEyre
RickEyre / prototype.js
Created February 25, 2015 16:22
Example of prototype JS
function Foo() {}
Foo.prototype.myState = {};
Foo.prototype.myBehaviour = function() {
console.log('Doing something');
}
foo = new Foo();
console.log(foo.state);
function UserFactory($http) {
var factory = {};
var users = {};
factory.load = function load() {
// Return promise returned by $http.get
return $http.get('http://localhost:3000/users')
.success(function(data) {
angular.forEach(data, function(item, index) {
users[data.id] = data;
@RickEyre
RickEyre / angularapp.js
Last active August 29, 2015 14:15
Basic Angular app
// Top level app folder
// app/js/app.js
angular.module('App', [ 'Components' ]);
// Top level components folder
// app/js/components/_module.js
angular.module('Components', [ 'Person' ]);
@RickEyre
RickEyre / json.js
Last active August 29, 2015 14:03
JSON
var obj = JSON.stringify(getMyJson());
console.log(obj.results.geomentry.location);