Skip to content

Instantly share code, notes, and snippets.

View Austio's full-sized avatar

Austin Story Austio

View GitHub Profile
@Austio
Austio / service_spec.js
Created March 3, 2017 22:58 — forked from paulsturgess/service_spec.js
Test Axios promise with jasmine-ajax
import Service from 'path/to/service';
import 'jasmine-ajax'
describe('Service', () => {
let request, promise;
let instance = Service;
let payload = {foo:'bar'};
let path = '/path';
let callback = jasmine.createSpy('callback');
@Austio
Austio / destructuring.js
Created September 17, 2016 10:51 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@Austio
Austio / protips.js
Created August 18, 2016 17:46 — forked from nolanlawson/protips.js
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
import { isLoggedIn } from '../../common/utils';
class App extends React.Component {
componentWillMount() {
isLoggedIn(); // is undefined
}
}
@Austio
Austio / tiny Promise.js
Created March 14, 2016 03:49 — forked from unscriptable/tiny Promise.js
A minimalist implementation of a javascript promise
// (c) copyright unscriptable.com / John Hann
// License MIT
// For more robust promises, see https://github.com/briancavalier/when.js.
function Promise () {
this._thens = [];
}
Promise.prototype = {
main.ts
import {provide} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {ROUTER_PROVIDERS, LocationStrategy, PathLocationStrategy, APP_BASE_HREF } from 'angular2/router';
import {HTTP_PROVIDERS} from 'angular2/http';
import {Notification} from './scripts/services/notifications';
import {SessionService} from './scripts/services/session.service';
import {UUHttp} from './scripts/services/uuHttp';
import {AppCmp} from './scripts/views/app';
app.ts
@RouteConfig([
{ path: '/login', name: 'Login', component: LoginFormCmp, useAsDefault: true },
{ path: '/home', name: 'Home', component: HomeCmp},
{ path: '/system/health', name: 'SystemHealth', component: SystemHealthCmp }
])
@Austio
Austio / Enum
Last active December 2, 2015 15:24
Error occuring when using active record enum inside of a nested active record class.
From: /../gems/activerecord-4.1.11/lib/active_record/attribute_methods.rb @ line 129 ActiveRecord::AttributeMethods::ClassMethods#method_defined_within?:
128: def method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc:
=> 129: if klass.method_defined?(name) || klass.private_method_defined?(name)
130: if superklass.method_defined?(name) || superklass.private_method_defined?(name)
131: klass.instance_method(name).owner != superklass.instance_method(name).owner
132: else
133: true
134: end
135: else
# Command Line to run from terminal
# Logs result to file s3_backup.log
# Command will run in the background
s3cmd sync -v /path/to/folder/ s3://s3-bucket/folder/ > s3_backup.log 2>&1 &
# Crontab command to sync folder to S3
# Command will run 1am every day and logs result to /root/s3_backup.log
0 1 * * * /usr/bin/s3cmd sync -rv /path/to/folder/ s3://s3-bucket/folder/ >> /root/s3_backup.log

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000