Skip to content

Instantly share code, notes, and snippets.

View djfarrelly's full-sized avatar
🌞

Dan Farrelly djfarrelly

🌞
View GitHub Profile
@djfarrelly
djfarrelly / index.js
Created June 9, 2014 17:40
requirebin sketch
var $ = require('jquery');
// I would assume this would work:
var DOMPurify = require('dompurify');
try {
var firstHTML = DOMPurify.sanitize('<p onclick="alert(10);">First worked</p>');
$('body').append( firstHTML );
} catch (err) {
$('body').append( '<p>' + err + '</p>' );
@djfarrelly
djfarrelly / shorten.js
Last active August 29, 2015 14:02
shorten function
// ==================== Existing =========================================
shorten: function(url, callback, reshortenLink) {
// ...
},
// called
Shortener.shorten('site.com/some/url', function(){
// more logic
}, true)
@djfarrelly
djfarrelly / placeholder-polyfill.js
Created July 10, 2014 23:08
jQuery placeholder polyfill using Modernizr
;(function($){
function inputFocus(){
var input = $(this);
if (input.val() === input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}
@djfarrelly
djfarrelly / index.js
Created August 12, 2014 22:37
requirebin sketch
var Levenshtein = require('levenshtein');
var titles = ["15 Twitter Hacks That Will Turn You Into a Twitter Ninja", "The Big List of Twitter Tools: 59 Free Twitter Tools and Apps to Fit Any Need", "Introducing Groups: The Easiest Way to Manage All Your Social Media Accounts With One Click", "What Really Happens When Someone Clicks Your Facebook Like Button"];
var currentTitle = "59 Free Twitter Tools and Apps That Do Pretty Much Everything";
function matchingWordsPercentage(orig, test) {
var origWords = orig.toLowerCase().split(' ');
var testWords = test.toLowerCase().split(' ');
@djfarrelly
djfarrelly / localDatabase.js
Last active August 29, 2015 14:06
db.js last modified
// deps:
// db.js = shared/libs/db.js
buffer.localDatabase = {
// Increase this to clear the db entirely
dbVersion: 1,
open: function() {
return db.open({
@djfarrelly
djfarrelly / ReactModal.jsx
Last active August 29, 2015 14:13
React modal for buffer
/* globals React */
/** @jsx React.DOM */
/**
* ReactModal
* Create your own React modal within a react component:
* render: function() {
* return (
* <ReactModal isOpen={this.props.isOpen}>
* <ReactModalHeader>
@djfarrelly
djfarrelly / QueueController.js
Created May 11, 2015 19:36
QueueController idea
/* globals React */
var Timeline = require('../shared/views/timelineReact.js');
var QueueHeader = require('../shared/views/queueHeader.js');
// buffer.View.CalendarPending
var QueueController = module.exports = {
_data: {
view: 'list'
},
@djfarrelly
djfarrelly / analyticsStore.js
Last active August 29, 2015 14:21
In an effort to more intelligently request data for sent updates
var AnalyticsStore = modules.exports = {
_data: new Backbone.Collection(),
_daysInCache: [],
grabDaysForCache: function(data) {
var days = data.updates.map(function(update){
return Math.r(update.due_at / 24 / 3600); // days since 1970
});
@djfarrelly
djfarrelly / Button.jsx
Last active August 28, 2015 18:22
style-guide
import classNames from 'classnames';
import getValidProps from '../lib/utils';
class Button extends React.Component {
render () {
var classes = classNames('Button', {
'Button--large': this.props.size === 'large',
'Button--small': this.props.size === 'small',
'Button--primary':this.props.primary,
'Button--hollow': this.props.hollow
@djfarrelly
djfarrelly / next.js
Created October 22, 2015 14:48
ES2015 intro chat
'use strict';
// What is ES2015?
// !!!!!!!!!!!!!! let, const !!!!!!!!!!!!!!!!!!!!!!
const ONE_HOUR = 60 * 60 * 1000;
ONE_HOUR = 60 * 60;
// Throws error