Skip to content

Instantly share code, notes, and snippets.

import React, {PropTypes, Component} from 'react'
import pureRender from 'pure-render-decorator'
import {Table, Column} from 'fixed-data-table'
import DataCellEditable from './data-cell-editable/'
import {List} from 'immutable'
import classnames from 'classnames'
import styles from './index.css'
@pureRender
export default class DataTableEditable extends Component {
import {default as React, PropTypes} from 'react'
const namespace = 'sampleComponent'
export default class SampleComponent extends React.Component {
getInitialState() {
return {value: ''}
}
handleInput(event) {
console.log('setting state to ', event.target.value)
@jmcelroy5
jmcelroy5 / index.html
Created December 28, 2014 21:51
TicTacToe
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tic Tac Toe</title>
<style>
#container{
width:330px;
height:330px;
// Creating a Backbone Model
var Person = Backbone.Model.extend({
// default attributes
urlRoot:'http://gdibb.herokuapp.com/people', // Is this where the URL goes?
defaults: {
role: 'hater',
imgUrl: 'http://uproxx.files.wordpress.com/2012/09/grumpy-cat-03.jpg',
firstName: 'Grumpy',
lastName: 'Cat'
},
@jmcelroy5
jmcelroy5 / gist:5310653aa393f6531e63
Last active August 29, 2015 14:10
Change map marker color when listing is clicked
Map.prototype.toggleMarkerColor = function(listingId){ // this is not running
alert("The map heard the click event!");
var idx = this.markerMap[listingId];
this.geoJson[idx].properties["marker-color"] = "#ffffff";
this.markerLayer.setGeoJson(this.geoJson);
this.markerLayer.addTo(this.map);
};
// Under Listings view...
@jmcelroy5
jmcelroy5 / gist:a12508f0d9ab886eb09a
Last active August 29, 2015 14:09
Flask OAuth for Facebook and BikeIndex
# Working code for Facebook's OAuth using Flask-OAuth library
from flask import session as flask_session
from flask_oauth import OAuth
oauth = OAuth()
facebook = oauth.remote_app('facebook',
base_url='https://graph.facebook.com/',
request_token_url=None,
In my javascript...
$.get('/get_all_bikes', function(data){
// All these print statements are all what I expect...
console.log("response from server:", data);
console.log("First item:", data['response'][0]);
console.log("Latitude is:", data['response'][0].latitude);
// But for loop is not running
@jmcelroy5
jmcelroy5 / gist:b27455eeb8ae0c94e46c
Created November 10, 2014 23:35
Flask function + Jinja template
// Flask function:
@app.route("/")
def home_page():
# Get first 10 bikes from database
bikes = model.session.query(model.Bike).limit(10).all()
return render_template("index.html", bikes=bikes)
// In Jinja template:
@jmcelroy5
jmcelroy5 / gist:cfe981c80da0d3612d60
Last active August 29, 2015 14:09
Redirects in JS/Flask
// AJAX post to add listing to database
$.post("/addlisting", {
price: price,
comments: comments,
latitude: latitude,
longitude: longitude
},
function(bike_id){ // returning bike_id with server response
window.location.href = "/listing/" + bike_id;
});
@jmcelroy5
jmcelroy5 / omg_unicode
Last active August 29, 2015 14:08
Working with unicode in python
def omg_unicode(some_input):
"""
Decode input immediately, work internally with unicode, encode at the end
Remember: Bytes in --> unicode everywhere --> bytes out
"""
# Decode your input (convert from <type 'str'> to <type 'unicode'>)
unicode_string = some_input.decode('utf8','ignore')
# Unicode all the things! (i.e. precede text with u and refer to non-ascii characters by their unicode code point)