Skip to content

Instantly share code, notes, and snippets.

View ipiyer's full-sized avatar

Prashanth Iyer ipiyer

  • San Francisco, CA
View GitHub Profile
const Promise = require("bluebird"),
_ = require("underscore");
var request = Promise.promisifyAll(Promise.promisify(require("request")));
function httpWrap(fn) {
return function() {
let args = _.toArray(arguments);
@ipiyer
ipiyer / gulp plugin returning promise
Created November 23, 2015 18:48
gulp plugin returning promise
const though = require("through2"),
syncDB = require("../syncdb");
module.exports = function() {
return through.obj(function(file, enc, cb) {
console.log(file.path, enc);
Vagrant.configure(2) do |config|
config.vm.hostname = "docker-host"
config.vm.box_check_update = false
config.vm.provider "docker" do |d|
d.image = "ubuntu"
end
config.ssh.username = 'docker'
@ipiyer
ipiyer / .js
Created December 29, 2015 23:56
terminate http stream
var request = require("request");
exports.foo = function(req, res) {
request.get("foo.com")
.on('response', function(){
if (response.statusCode === 404) {
// terminate and return {"error": "not found"}
// How do i do this?
}
})
@ipiyer
ipiyer / .js
Created January 19, 2016 04:38
Model methonds
let User = bookshelf.Model.extend({
tableName: 'user',
idAttribute: 'id',
hasTimestamps: ["updated_at", "created_at"],
socialAccount: function() {
return this.hasMany(UserSocialAccount);
},
findById: function(id) {
return this.where({
id: id
@ipiyer
ipiyer / .js
Last active February 7, 2016 02:54
FRP username validation
// username is a input element in the dom
let userNameVal = Kefir.fromEvents(username, "blur")
.map(e => $(e.target)
.val());
let kUsernameValidation = username => {
try {
if (usernameValidation(username)) {
return username;
@ipiyer
ipiyer / .js
Created February 7, 2016 03:18
Express + postgres + knex + bookshelf example
const session = require('express-session'),
pg = require("pg"),
pgSession = require('connect-pg-simple')(session);
const pgConnection = {
host: 'localhost',
user: 'blahblah',
database: 'foobar',
charset: 'utf8'
}
@ipiyer
ipiyer / pod
Last active January 22, 2017 04:07
postgres kubernetes gcp
apiVersion: v1
kind: Pod
metadata:
name: pg
labels:
name: pg
spec:
securityContext:
fsGroup: 999
containers:
@ipiyer
ipiyer / pcm_audio_length.js
Created November 4, 2017 18:29
calculate pcm audio length
const { Transform } = require("readable-stream");
const fs = require('fs');
class PCMTime extends Transform {
constructor() {
super();
this.length = 0;
// bitsPerSample * samplesPerSecond * channels
this.bytesPerSec = (16 * 44100 * 1) / 8;
@ipiyer
ipiyer / .js
Last active January 5, 2018 19:35
const { Transform } = require('stream');
const {aStream, bStream } = require("other_file");
class Convert extends Transform {
constructor() {
super();
this.aStream
.pipe(bStream)
bStream
.on('data', data => this.cb(null, this.chunk));