Skip to content

Instantly share code, notes, and snippets.

View Willmo36's full-sized avatar

Max Willmott Willmo36

  • SkipTheDishes
  • Saskatoon
View GitHub Profile
@Willmo36
Willmo36 / JavaScript example
Created March 9, 2013 19:52
JavaScript example. Controller in for a NodeJS app.
var userController = module.exports = {
register:function (req, res, next) {
var postValues = req.body;
var newUser = new userModel();
newUser.saveAndGetErrors(postValues, function(user){
req.session.loggedIn = true;
req.session.userId = user._id;
if(req.body.returnUrl) res.redirect(res.body.returnUrl);
else res.render("/user/profile", {user:user});
},
@Willmo36
Willmo36 / ngModelExtention
Last active August 29, 2015 13:57
Extending ngModel
app.directive('ngModel', ['$timeout',function($timeout) {
return {
require: 'ngModel',
restrict: 'A',
link: function(scope, element, attrs, model) {
var timer,
delay = 1000;
element.bind('keydown change input', function () {
if (timer) {
npm config edit
change all '\\files' to the local appdata folder eg
'\\files\home\maxwillmott\AppData\Roaming\npm\node_modules'
to
'C:\Users\maxwillmott\AppData\Roaming\npm\node_modules'
stuff still won't execute though (karma). create a batch file in the working directory pointing to the relavant command eg
@Willmo36
Willmo36 / RunRouteActions.js
Created January 20, 2015 17:25
Run actions on active routes
//This could be massively improved and documented
function RunRouteActions(dispatcher, routes, state){
var actionsToRun = [];
var actionIndex = 0;
var activeRouteNames = state.routes.map(function (route) {
return route.name;
});
@Willmo36
Willmo36 / Rx.Observable.fromSuperagent.es6
Last active July 21, 2016 19:03
RxJS stream from SuperAgent request
let Rx = require("rx");
Rx.Observable.fromSuperagent = request => () => Rx.Observable.create(observer => {
request.end((err, res) => {
if (err) {
observer.onError(err)
} else {
observer.onNext(res);
}
observer.onCompleted();
@Willmo36
Willmo36 / kefir-superagent.js
Created February 25, 2015 12:54
Superagent request with kefir
let requestStream = Kefir.emitter();
let responseStream = requestStream.map(url => {
return Kefir.fromCallback(cb=> request.get(url).end(cb));
}).flatMap();
responseStream.onValue(v=>{
console.log("kefir log",v);
});
requestStream.emit("data.json");
@Willmo36
Willmo36 / KefirFluxStore.js
Last active August 29, 2015 14:16
Kefir flux store example
let Kefir = require("kefir");
function BlogStore(actions, initialState) {
//map the action stream to a stream which returns a function which modifies the state.
let createPost = actions.Post.create.map((newPost) => {
//the scan method will call this with the current vaule (allPosts)
return (allPosts) => {
allPosts.push(newPost);
@Willmo36
Willmo36 / delete-old-chunk-files.js
Created March 25, 2015 11:05
Delete old chunk files
plugins: [
function () {
var distPath = "./dist";
this.plugin("done", function (stats) {
var finalFile = stats.toJson().assetsByChunkName.main;
fs.readdirSync(distPath).forEach(function (filename) {
if (filename !== finalFile) {
fs.unlinkSync(distPath + filename);
}
})
@Willmo36
Willmo36 / d3-tip-browserify.js
Created March 30, 2015 10:14
d3-tip with browserify and webpack
let d3 = require("d3");
let d3tip = require("d3-tip");
d3tip(d3);
@Willmo36
Willmo36 / request-rx.js
Created April 14, 2015 10:47
request-rx.js
'use 6to5';
const rx = require('rx');
const request = require('request');
const fs = require('fs');
let wrapMethodInRx = (method) => {
return function(...args) {
return rx.Observable.create((subj) => {
// Push the callback as the last parameter