Skip to content

Instantly share code, notes, and snippets.

View davidfurlong's full-sized avatar
👨‍💻

David Furlong davidfurlong

👨‍💻
View GitHub Profile
Add to header (after selectize.css)
<style>
.selectize-input input[type="text"] {
border:1px solid #d0d0d0 !important;
background:white !important;
padding:4px !important;
min-width:100px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
@davidfurlong
davidfurlong / order statistic tree.js
Last active January 18, 2021 14:55 — forked from trevmex/bst.js
Order statistic tree (Binary Search Tree with Rank and Size)
// Use: var tree = new OST(); tree.select(4); tree.insert(key,value)
var OST = function () {
// Order statistic tree node
var Node = function (leftChild, key, value, rightChild, parent) {
return {
leftChild: (typeof leftChild === "undefined") ? null :
leftChild,
key: (typeof key === "undefined") ? null : key,
value: (typeof value === "undefined") ? null : value,
rightChild: (typeof rightChild === "undefined") ? null :
@davidfurlong
davidfurlong / proximitysearch.js
Created July 30, 2014 23:02
Proximity Search
// Returns the score if within the proximity, else returns -1
Array.prototype.indexOfAll = function(term) {
if(typeof term == 'object'){
console.error('indexOfAll expects an array of terms as an argument');
return;
}
var posOfTerms = [];
for(i in this){
if(this[i] == term){

Keybase proof

I hereby claim:

  • I am davidfurlong on github.
  • I am graph (https://keybase.io/graph) on keybase.
  • I have a public key whose fingerprint is 09E5 4284 984D BE6D 3338 5A78 52BB 204B 2564 24F7

To claim this, I am signing this object:

@davidfurlong
davidfurlong / stickfooter.css
Created October 15, 2014 18:37
Sticky footer that actually works
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 100px; /* bottom = footer height */
}
footer {
position: absolute;
left: 0;
var Col = require('react-bootstrap/lib/Col')
var PageHeader = require('react-bootstrap/lib/PageHeader')
var React = require('react')
var Row = require('react-bootstrap/lib/Row')
var {connect} = require('react-redux')
var {reduxForm} = require('redux-form')
var DateInput = require('./DateInput')
var FormField = require('./FormField')
var LoadingButton = require('./LoadingButton')
@davidfurlong
davidfurlong / Bookshelf-postgis.md
Last active February 28, 2022 05:47
Use Bookshelf with postgis and knex-postgis without the hassle

How to use Bookshelf with postgis and knex-postgis without the hassle

Using Bookshelf.js with postgis and knex-postgis is a huge pain in the ass.

TLDR - Override Bookshelf methods to parse postgis formats in JS, not in SQL to avoid having to do awkward Bookshelf modifications anywhere you make a bookshelf insert/update/delete on Geo data (middleware like approach)

class Event extends Bookshelf.Model {
  get tableName() { return 'event'; }
@davidfurlong
davidfurlong / disableSSR.js
Last active March 16, 2017 14:25
disable server side rendering for a react component [hacky]
/*
A react higher order component (HOC) for disabling server side rendering (SSR) for a particular component.
Useful if a particular library / page doesn't support SSR and you
a) dont want to mess around with the server routing to handle it
b) dont want to the component to even be constructed on the server
c) dont want to modify the component's methods to handle loading the library on the client
(for example, you need to use window/client methods in the constructor)
DISCLAIMER: this is hacky, and will throw a console warning (in development) that the checksum is invalid (which means server & client rendering dont agree on HTML string)
@davidfurlong
davidfurlong / statelessHOCwithContext.js
Created March 26, 2017 12:57
React HOC which returns a Stateless Functional component which has contextTypes or defaultProps or propTypes
/* its not immediately obvious how to do this, which is why I've added it here */
const connectSubmitButton = (WrappedComponent) => {
const connectContext = (props, context) => (<WrappedComponent {...props} _reduxForm={context._reduxForm} />);
connectContext.contextTypes = {
_reduxForm: PropTypes.object.isRequired
};
return connectContext;
};
@davidfurlong
davidfurlong / conditional_js_property.js
Created April 17, 2017 07:34
Conditional js property
const _ = (obj, cond = (val) => typeof val === 'undefined' || val === null) =>
Object.assign({},
...(Object.keys(obj).map(key =>
cond(obj[key]) ? {} : {
[key]: obj[key]
})
)
);
/*