Skip to content

Instantly share code, notes, and snippets.

View newsomc's full-sized avatar

Clint Newsom newsomc

View GitHub Profile
@newsomc
newsomc / validate-input-component.coffee
Created May 1, 2014 23:22
Validation of a react component.
Validate = {
getDefaultProps: ->
validate: []
hasErrors: ->
errors = []
@validate.forEach (cond) =>
if cond.test(@state.value)
errors.push(cond.message)
from requests_oauthlib import OAuth1Session
from flask import Flask, request
from flask.json import jsonify
import os
app = Flask(__name__)
# Get the access token from the environment variables
api_key = os.environ.get('BEATPORT_API_KEY', None)
api_key_secret = os.environ.get('BEATPORT_API_KEY_SECRET', None)
@newsomc
newsomc / beatport-auth.py
Created December 15, 2013 16:06
Beatport OAuth 1.0 documentation: https://oauth-api.beatport.com/
from requests_oauthlib import OAuth1Session
from flask import Flask, request, redirect, session, url_for, current_app
from flask.json import jsonify
import os
import urllib
app = Flask(__name__)
# This information is obtained upon registration of a new Bp
client_id='<key>'
(defn computer-down? [{{computer-y :y} :computer
{ball-y :y} :ball player-height :player-height :as state}]
(and (> (- computer-y 20) ball-y) (>= (- computer-y (/ player-height 2)) 0)))
;; vs.
(defn computer-down? [{:keys [ball computer] :as st}]
(let [cy (:y computer)]
(and (> (- cy 20) (:y ball))
(>= (- cy (/ (:player-height st) 2)) 0))))
@newsomc
newsomc / thie-little-javascripter.js
Created October 31, 2013 14:16
The Little JavaScripter
// The Little JavaScripter
// http://www.crockford.com/javascript/little.js
// Copyright 2003 Douglas Crockford. All rights reserved wrrrld wide.
// May 4, 2011
// Produce a printable presentation of an s-expression
function p(x) {
class bBox
bboxstr: "-74.0045051,40.7558605,-73.994675,40.7627951"
zoom: 18
getTiles: (bboxstr, zoom) ->
bboxarr = bboxstring.split ","
if (bboxarr.length != 4)
true
bbox = new L.latLngBounds new L.latLng(bboxarr[1], bboxarr[0]) , new L.latLng(bboxarr[3], bboxarr[2])
NW = bbox.getNorthWest()
#!/bin/bash
echo Removing moving modules from git repository and drupal database.
modules=( "signup" "recaptcha" "captcha" "spamicide" "badbehavior" "apc" "google_website_optimizer" "context" "date_context" "garland" "shrew" "taxonomy_manager" "customerror" "jquery_ui" "nypl_bibliocommons" )
libraries=( "simplepie" "awssdk" )
for module in "${modules[@]}"
do
drush dis $module -y
git rm --cached sites/all/modules/$module
git rm -r .git/modules/sites/all/modules/$module
rm -r sites/all/modules/$module
@newsomc
newsomc / core.clj
Created September 9, 2013 14:54 — forked from llasram/core.clj
(ns lenskit-hello.core
(:require [clojure.java.io :as io])
(:import [org.grouplens.lenskit
ItemRecommender ItemScorer Recommender RecommenderBuildException]
[org.grouplens.lenskit.baseline
BaselineScorer ItemMeanRatingItemScorer UserMeanBaseline
UserMeanItemScorer]
[org.grouplens.lenskit.core
LenskitConfiguration LenskitRecommender]
[org.grouplens.lenskit.cursors Cursors]
@newsomc
newsomc / async.js
Last active December 20, 2015 21:19
A revised example from http://css-tricks.com/thinking-async/. See under the section "Cleaning House". This version pulls a list of scripts from Drupal.
/**
* PHP would look something like this (it could be in a module or theme):
* The list of scripts could be set somewhere in Drupal's admin interface.
*
* <?php
* define(SCRIPTS, variable_get('external_scripts'));
* drupal_add_js(array('my_module' => SCRIPTS), 'setting');
* ?>
*/
options("repos"="http://cran.us.r-project.org")
library("rgdal")
myPolygons = readOGR("/path/to/file",layer="mylayer")
alpha=0.75
library(alphahull)
pts = spsample(myPolygons, n=1000, type="regular")
x.as = ashape(coordinates(pts),alpha=alpha)
# need to convert x.as to a SpatialPolygon
# code to convert ahull into sp: