Skip to content

Instantly share code, notes, and snippets.

View JonAbrams's full-sized avatar

Jon Abrams JonAbrams

View GitHub Profile
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}`);
@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.
invalid_user = User.find_each.find(&:invalid?)
invalid_users = User.find_each.select { |user| user.invalid? }
# or
invalid_users = User.find_each.select(&:invalid?)
User.where('last_seen < ?', 2.months.ago).find_each do |user|
user.send_reminder!
end
@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;
@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 / 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 {};
### 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:af4020ea3dd31cf3ffc2
Created September 18, 2014 21:10
Scrape list of URLs and prints them - Uses promises
var Promise = require('bluebird'); // The best promise library out there
var request = require('request-promise'); // Scrapes the specified url, returns promise e.g. request(url)
var urls = process.argv.slice(2); // List of URLs to scrape
Promise.map(urls, request) // Returns an array of promises to the results of scraping the url
.each(console.log) // Call console.log on each resolved promise
.catch(console.error);