Skip to content

Instantly share code, notes, and snippets.

@saadtazi
saadtazi / README.md
Created June 6, 2019 01:28
NATS.io TLS only Client

See nats-io/nats-server#291

This allowed us to use AWS ELB with TLS termination.

We just copied _select_next_server(self) and modified around lines 47 and 59 (define and add ssl params at line 59).

A better solution would be change the default NATS client (in the main package):

  • have a default_dialer() method that wraps the asyncio.open_connection() call
  • add a custom_dialer parameter in the __init__() constructor. self.dialer should be set to self.default_dialer if custom_dialer is None.
  • call self.dialer() instead of asyncio.open_connection().
@saadtazi
saadtazi / negative_review.py
Last active October 29, 2018 13:56
Udacity Sentiment RNN - bad negative prediction
# from https://github.com/udacity/deep-learning-v2-pytorch/blob/f456d6167d8af205154cd27f0bcfe5eb813e2503/sentiment-rnn/Sentiment_RNN_Solution.ipynb
# at the end of the notebook...
rev1= 'this film is one giant pant load . paul schrader is utterly lost in his own bad screenplay . and his directing is about as comatose as it can be without his actually having been sleepwalking during the process . br br the worst though is woody harrelson whom i ordinarily like when he s properly cast . he plays the walker a homosexual man in d . c . who plays social companion to the bored wives of the washington elite . he couldn t have been more one dimensional if he had been cut out of a magazine and bounced around in front of the camera on a popsicle stick . his southern accent is that off the rack version that decrescendos from the beginning to the end of every line he delivers as though the heat and humidity of the south is still draining him of every ounce of energy he has . it is monotonous . but his
@saadtazi
saadtazi / resize-aware.js
Last active November 15, 2017 01:40
WindowResizeListener
class ResizeListener extends React.Component {
state = {}
getWindowSize() {
return {
innerWidth: window.innerWidth,
innerHeight: window.innerHeight,
};
}
changeState = () => {
const newSize = this.getWindowSize();

Keybase proof

I hereby claim:

  • I am saadtazi on github.
  • I am saadtazi (https://keybase.io/saadtazi) on keybase.
  • I have a public key whose fingerprint is 78B4 2FA5 013D 68F6 067B EA38 7738 B8C9 6C90 A7B8

To claim this, I am signing this object:

@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;
@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 / 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 / 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 / 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 / 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: {