Skip to content

Instantly share code, notes, and snippets.

function Solver(startCoconuts, sailors) {
this.coconuts = startCoconuts;
this.sailors = sailors;
this.calls = 0;
}
Solver.prototype.canBeDividedBySailorsMinusOne = function() {
if ((this.coconuts / (this.sailors - 1)) % 1 === 0) {
return true;
}
@sean-nicholas
sean-nicholas / es6_angular_di.js
Created March 8, 2016 11:11
Test for es6 angular dependency injection
function getThem(args) {
var obj = [];
//'(a, b, c, d, e, f)'
console.log(args.callee.toString());
var tmp = args.callee.toString().match(/\(.*?\)/g)[0];
//["a", "b", "c", "d", "e", "f"]
var argumentNames = tmp.replace(/[()\s]/g,'').split(',');
var list = {};
[].splice.call(args,0).forEach(function(arg,i) {
@sean-nicholas
sean-nicholas / TimelineLoading.vue
Last active June 12, 2016 17:55
Vue.js with webpack template & dynamics.js
<script>
import dynamics from 'dynamics.js'
import _ from 'lodash'
export default {
data () {
return {
dotCount: 3
}
},
@sean-nicholas
sean-nicholas / backup.sh
Created September 27, 2016 09:05
Simple Backup Script
#!/bin/bash
exec &>> backup_log.txt
DATE=`date +%Y-%m-%d`
SOURCE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/."
TARGET="___SOME_PATH___/${DATE}"
echo "${DATE}: Starting Backup"
mkdir -p ${TARGET}
cp -ar ${SOURCE} ${TARGET}
@sean-nicholas
sean-nicholas / auto-logout.js
Last active March 20, 2019 09:46
Auto Logout
const store = require('store');
const MINUTES_UNITL_AUTO_LOGOUT = 5 // in mins
const CHECK_INTERVAL = 1000 // in ms
const STORE_KEY = 'lastAction';
class AutoLogoutService {
get lastAction() {
return parseInt(store.get(STORE_KEY));
@sean-nicholas
sean-nicholas / index.js
Last active March 7, 2018 13:35
issue feathers-hooks-common alterItems
const { alterItems } = require('feathers-hooks-common');
function getPromise() {
return new Promise(res => setTimeout(() => res('something'), 500))
}
const context = {
type: 'after',
method: 'get',
result: {
@sean-nicholas
sean-nicholas / frxau_prepend.js
Last active March 24, 2018 12:17
feathers-reactive with Angular Universal - prepend
app.service(‘products’).watch().find()
@sean-nicholas
sean-nicholas / frxau_init.js
Last active March 24, 2018 12:17
feathers-reactive with Angular Universal - init
import feathers from '@feathersjs/feathers'
import * as io from 'socket.io-client'
import socketio from '@feathersjs/socketio-client'
import * as rx from 'feathers-reactive'
const app = feathers()
const socket = io(BASE_URL)
app
.configure(socketio(socket))
.configure(rx({ idField: '_id' }))
@sean-nicholas
sean-nicholas / frxau_data_1.ts
Created March 24, 2018 12:20
feathers-reactive with Angular Universal - data 1
@Injectable()
export class DataService {
constructor(
) {
const socket = io(this.BASE_URL)
this.app
.configure(socketio(socket))
.configure(rx({ idField: '_id' }))
}
@sean-nicholas
sean-nicholas / frxau_rx-universal.ts
Created March 24, 2018 12:41
feathers-reactive with Angular Universal - rx universal
import { Observable } from 'rxjs/Observable'
export function rxUniversal(options = {}) {
const mixin = function (service) {
const app = this
const serviceMixin = {
watch(watchOptions = {}) {
const methods = {}