Skip to content

Instantly share code, notes, and snippets.

View colonelrascals's full-sized avatar
:shipit:

Patrick Hildreth colonelrascals

:shipit:
View GitHub Profile
//------------------------------------------------------------------------->
// Models
//------------------------------------------------------------------------->
//api_key = nj5ttz726ygmvar5bqvl1cjh
var EtsyCollection = Backbone.Collection.extend({
url: 'https://openapi.etsy.com/v2/listings/active.js',
parse: function(apiResponse) {
return apiResponse.results
}
@colonelrascals
colonelrascals / hemingway-fibonacci.js
Last active April 21, 2017 04:29
Hemingway did fibonacci
// Ernest Hemingway
function fibonacci(size) {
var first = 0, second = 1, next, count = 2, result = [first, second];
if(size < 2)
return "the request was made but it was not good"
while(count++ < size) {
## Classes
Classes are like blueprints for creating Objects in a language. The object created using a class is called an instance. That said, the `class` keyword in JavaScript is new to ES6. This new keyword (`class`) makes using what we call "prototypes" easier than in the past, while glossing over some of the intricacies. A "prototype" in JavaScript is actually just a "fallback" mechanism. If the instance does not have a particular property or method, then JavaScript will "fall back" to the prototype and look there. Don't get too caught up in this "prototype chain" now, you'll read more about this later.
> Note that "classes" in JavaScript are very different from other languages. The underlying differences are a bit complex, and for now you can think of the two paradigms as the same, but know that in the future you might need to explore those differences.
We call JavaScript's object system "prototypical" (or "prototypal") whereas the object system in Java, for example, would be called "class-based". Don'
//this is how .map works!!!
Array.prototype.mapOver = function(callback) {
var newArray = [] // since we're returning an array, we'll start with an empty vessel for the contents of that array.
for (var i = 0; i < this.length; i ++) { // we're iterating over *the array that is calling* the method.
newArray.push(callback(this[i])) // we invoke the callback with an array element as input, and we push the return value onto our new array.
}
return newArray // .map(), unlike .forEach(), has a return value
}
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from itertools import chain
import datetime
import hashlib
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django_mysql.models import JSONField, Model
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from itertools import chain
import datetime
import hashlib
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django_mysql.models import JSONField, Model
class Bookmark(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
resource = models.ForeignKey("Resource", on_delete=models.CASCADE, related_name="bookmarks")
# meta
created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True)
class Meta:
unique_together = ('user', 'resource',)
ordering = ('resource',)
class BookmarkMetaSerializer(serializers.ModelSerializer):
class Meta:
model = Bookmark
fields = '__all__'
class BookmarkGroupSerializer(serializers.ModelSerializer):
class Meta:
model = BookmarkGroup
fields = '__all__'
const Bookmark = ({ clickHandler, icon, tooltip, bookmarkId }) => (
<DropdownButton
title={ <i className={`fa fa-${icon} fa-lg`} aria-hidden="true" /> }
bsSize="small"
noCaret
>
<MenuItem eventKey="1" onClick={() => clickHandler()} >Food</MenuItem>
<MenuItem eventKey='2' onClick={() => clickHandler()} >Transportation</MenuItem>
<MenuItem eventKey='3' onClick={() => clickHandler()} >Utilities</MenuItem>
<MenuItem eventKey='4' onClick={() => clickHandler()}>Add/Remove Bookmark</MenuItem>
export default class ResourcePanel extends React.Component {
constructor(props) {
super(props);
this.state = {
isBookmark: !_.isEmpty(props.data.bookmark),
inPrintQueue: false, // we assume not because we don't map this onto data model currently...
shareModalOpen: false,
correctModalOpen: false,
hasPdf: false
};