Skip to content

Instantly share code, notes, and snippets.

View jadehopepunk's full-sized avatar

Jade jadehopepunk

  • Melbourne, Australia
View GitHub Profile
function isValidOrder(order, customer) {
const salesTaxPercentage = 0.15
return
order.units > 1 &&
order.state == 'complete' &&
order.price * (1.0 + salesTaxPercentage) < customer.availableBalance
}
@jadehopepunk
jadehopepunk / cookbook.py
Created September 17, 2016 23:22
django graphene cookbook schema
# cookbook/ingredients/schema.py
from graphene import relay, ObjectType
from graphene.contrib.django.filter import DjangoFilterConnectionField
from graphene.contrib.django.types import DjangoNode
from cookbook.ingredients.models import Category, Ingredient
# Graphene will automatically map the Category model's fields onto the CategoryNode.
# This is configured in the CategoryNode's Meta class (as you can see below)
module PersonRow exposing (..)
import Html exposing (..)
import Html.App as App
import WeekButtons
-- MODEL
type alias Model = {
@jadehopepunk
jadehopepunk / model_enricher.js
Created December 13, 2015 19:23
Model enrichment on the client side for GetStream.io
import ModelStore from './model_store'
class ModelEnricher {
constructor() {
this.modelStore = new ModelStore();
}
enrichAggregateResult(result, onSuccess) {
const modelKeys = this.modelKeys(result.results);
this.modelStore.loadModels(modelKeys, (results) => {
module.exports = () ->
request = require('request').defaults(
headers:
'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0',
'Accept-Language': "en-US,en;q=0.5",
'Connection': "keep-alive"
)
cheerio = require('cheerio')
request.post 'https://fetlife.com/session', {jar: true, followRedirect: true, form: {nickname_or_email: 'make-you-a-man', password: 'studmuffin', utf8: '✓'}}, (error, response, body) ->
class IndentManager
def initialize
@indents = []
@parse_complete = false
end
def register_indent(indent)
@indents << indent
end
@jadehopepunk
jadehopepunk / gist:7f20595d55becd39fd4d
Last active August 29, 2015 14:05
cobudget schema
class CreateInitialDb < ActiveRecord::Migration
def change
create_table :people do |t|
end
create_table :buckets do |t|
end
create_table :budgets do |t|
end
@jadehopepunk
jadehopepunk / gist:9609833
Last active August 29, 2015 13:57
output more logging stuff
module Xeroizer
module Http
private
def http_request(client, method, url, body, params = {})
# headers = {'Accept-Encoding' => 'gzip, deflate'}
@jadehopepunk
jadehopepunk / week.rb
Created October 1, 2013 23:28
A Week class (which extends a Range of dates). Relies on Monthify to provide the months
require 'monthify'
module Weekify
module HasWeeks
def to_weeks
(Week.containing(first_day))..(Week.containing(last_day))
end
end
class DateRange < Range
@jadehopepunk
jadehopepunk / jQuery Plugin
Last active December 20, 2015 23:58
A coffee script version of the jQuery plugin structure outlined at http://engineering.yp.com/post/jquery-oo-plugins
class MyPlugin
constructor: (element, options) ->
@elem = $(element)
@settings = $.extend(param: "defaultValue", options or {})
# Public method
publicMethod: () ->
console.log "publicMethod() called!"
$.fn.myplugin = (options) ->