Skip to content

Instantly share code, notes, and snippets.

View JonAbrams's full-sized avatar

Jon Abrams JonAbrams

View GitHub Profile
### Keybase proof
I hereby claim:
* I am JonAbrams on github.
* I am jonabrams (https://keybase.io/jonabrams) on keybase.
* I have a public key whose fingerprint is 85C9 3D40 9117 7873 F035 F412 DD07 CC1A 9A43 AED2
To claim this, I am signing this object:
@JonAbrams
JonAbrams / gist:3b06be7f612c6e0cf6e0
Last active August 29, 2015 14:13
Safe JSON.parse
(function () {
var ogJSONParse = JSON.parse;
JSON.parse = function (text, reviver) {
try {
return ogJSONParse(text, reviver);
} catch (err) {
console.error('Failed to parse: ', text);
console.error(err.stack);
return {};
@JonAbrams
JonAbrams / gist:7edaa3545f8fd11a1919
Created July 9, 2015 23:15
How to add getter/setter methods to ES6 classes after the class is created
// Also works for normal methods
class User {
constructor (first, last) {
this.firstName = first;
this.lastName = last;
}
}
Object.defineProperty(User.prototype, 'name', {
get: function () {
@JonAbrams
JonAbrams / jstz-fix.js
Created March 29, 2016 16:33
jstz minus Intl
var oldIntl = window.Intl;
window.Intl = undefined;
var tzName = jstz.determine();
window.Intl = oldIntl;
User.where('last_seen < ?', 2.months.ago).find_each do |user|
user.send_reminder!
end
invalid_users = User.find_each.select { |user| user.invalid? }
# or
invalid_users = User.find_each.select(&:invalid?)
invalid_user = User.find_each.find(&:invalid?)
@JonAbrams
JonAbrams / SegmentLoader.js
Last active October 19, 2017 21:47
React component for loading Segment's library
import React from 'react';
import { string } from 'prop-types';
class SegmentLoader extends React.Component {
componentDidMount() {
const { segmentWriteKey } = this.props;
// Create a queue, but don't obliterate an existing one!
const analytics = (window.analytics = window.analytics || []);
// If the real analytics.js is already on the page return.
// If no write key is provided return.
import Space from 'spaceace';
const space = new Space({
appName: "SpaceAce demoe",
user: { name: 'Jon', level: 9001 }
});
const newSpace = space({ appName: "SpaceAce demo" });
console.log(`Old app name: ${space.appName}, new app name: ${newSpace.appName}`);
import Space, { subscribe } from 'spaceace';
const space = new Space({
appName: "SpaceAce demoe",
user: { name: 'Jon', level: 9001 }
});
subscribe(space, ({ newSpace, causedBy }) => {
console.log(`State updated by ${causedBy}`);
ReactDOM.render(