Skip to content

Instantly share code, notes, and snippets.

@saadtazi
saadtazi / README.md
Last active December 12, 2015 08:09
canjs google analtyics plugin

Usage

A canjs Control that setup Google Analytics (injects JS) and can automatically:

  • track hashChange (on or off) as pageView
  • track any can.Model / Observe / Model.List / Observe.List events as Google Analytics events

Observe Event

can.Model.List.prototype.filter = function(cb) {
var res = [];
debugger;
this.each(function(amodel, pos, models) {
var ares = cb.call(amodel, pos, models);
if (ares === true) {res.push(amodel)}
});
return res
}
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@saadtazi
saadtazi / mstl.js
Created September 27, 2013 01:29
requireJS plugin that compiles mustache template. Templates are added and automatically registered in your compiled js file using r.js.
/*
* requirejs plugin that loads mustache templates from the baseUrl and registers it in can.view
* Optimize/compiles/minifies the templates when the requirejs optimizer is run
* usage:
* require([
..,
'mustl!path/to/mustache/tmp.mustache' // no need to add a var in callback function for your template
], function () {})
*/
@saadtazi
saadtazi / Gruntfile.js
Created April 19, 2014 01:18
grunt-mocha-webdriver bootstrap
module.exports = function(grunt) {
'use strict';
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
// ....
mochaWebdriver: {
options: {
@saadtazi
saadtazi / index.html
Created May 2, 2014 18:13
avatar using arrow form
<html>
<head>
<style type="text/less">
@bgColor: #ccc;
@avatarHeight: 20px;
@imageWidth: 64px;
body {
background-color: @bgColor;
}
@saadtazi
saadtazi / Promise.props without bluebird.md
Last active July 20, 2023 12:02
buebird inspired Promise.props using native Promise.all()

Usage

Promise.props({ a: 1, b: Promise.resolve(14) }).then(function (a) {
    console.log('resolved:::', a);
});
/// resolved::: { a: 1, b: 14 }

Promise.props({ a: 1, b: Promise.reject(14) }).catch(function (err) {
 console.log('rejected:::', err);
@saadtazi
saadtazi / README.md
Last active May 1, 2019 12:11
Phantomjs login + nodejs requests (after getting cookies)
  1. npm install

  2. To test that phantomjs works as expected: ./node_modules/.bin/phantomjs phantom-script.js USERNAME PASSWD

  3. Then run it from nodejs: node phantom.js (the username and password are hardcoded in this file for now...)

The phantom.js script just proves that it works, by checking the "username" in the top right corner of the Premier homepage.

Note that it still takes about 6 seconds for phantomjs to login into QA.

@saadtazi
saadtazi / README.md
Last active April 9, 2016 18:27
Promise polling

Usage

promisePoll(
  // a function that takes no param and return a promise
  // `.bind(...)` as much a you want!
  () => { return aPromise; },
  // a function that will be called with the resolved value
  // of return value of the first function
  // and that should return true if the condition is satisfied
@saadtazi
saadtazi / app.js
Created July 19, 2016 11:52
passport multiple strategies
const express = require('express');
const cons = require('consolidate');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const passport = require('passport');
const FacebookStrategy = require('passport-facebook').Strategy;
const LocalStrategy = require('passport-local').Strategy;
const ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;