Skip to content

Instantly share code, notes, and snippets.

@fbatroni
fbatroni / dev_random.py
Created January 16, 2018 22:19
Example of python implementation of /dev/random
#!/usr/bin/env python
import os
import argparse
import binascii
from sys import argv, stdout
# default values
DEFAULT_ENTROPY = 4096*16
@fbatroni
fbatroni / gist:0ce8a548d2e64d45bcc00142739eca06
Created December 28, 2017 01:35
ES6 Class With Inheritance
'use strict';
const EventEmitter = require('events').EventEmitter;
const SomeClass = (() => {
class SomeClass extends SomeOtherClass {
constructor() {
super();
EventEmitter.call(this);
}
#!/usr/bin/python

 # function that accepts 2 arrays. 
 # The arrays contain numbers and each input array is already sorted in increasing order. 
 # The function should create and return another array which contains all of the numbers that are in the 2 input arrays. 
 # The numbers in the returned array should also be sorted in increasing order
 # Example usage: python process_numbers.py [1,10,3,22,23,4,2,200,201,202,203,204,205,206,207,207,209] [5,8,9,11,25]
 
import sys
/* Sample JavaScript file added with ScriptTag resource.
This sample file is meant to teach best practices.
Your app will load jQuery if it's not defined.
Your app will load jQuery if jQuery is defined but is too old, e.g. < 1.7.
Your app does not change the definition of $ or jQuery outside the app.
Example: if a Shopify theme uses jQuery 1.4.2, both of these statements run in the console will still return '1.4.2'
once the app is installed, even if the app uses jQuery 1.9.1:
jQuery.fn.jquery => "1.4.2"
$.fn.jquery -> "1.4.2"
*/
@fbatroni
fbatroni / backup_git_repos.sh
Created February 4, 2015 20:07
Shell script that pulls down and clones all available repos for an organization - can be used as a "backup" utility
#!/bin/bash
#Shell script that pulls down and clones all available repos for an organization - can be used as a "backup" utility
#Pre-reqs = jsawk https://github.com/micha/jsawk
#don't forget to export out your username and password as variables or maybe add a couple of parameters to accept them as input args
#export GITHUB_USERNAME=my_github_username
#export GITHUB_PASSWORD=my_github_password
echo "getting list of available repos"
PAGE_NUMBER=1
ORG=$1
@fbatroni
fbatroni / configure_elasticsearch_rivers.sh
Created January 27, 2015 17:37
Dynamically add mongo collections to ElasticSearch mongodb river
#!/bin/bash
PWD=`pwd`
echo "configuring es_river(s)"
# return a list of collections except the system tables
collections=`mongo --host ${MONGODB_SERVER} --username ${MONGODB_USER} --password ${MONGODB_PASSWORD} ${MONGODB_DATABASE} --eval 'db.getCollectionNames().filter(function (c) { return /^((?!system).)*$/.test(c) && /^((?!sessions).)*$/.test(c) })' | sed -n '3p' | sed 's/,/ /g'`
echo "collections: ${collections}"

Pub/sub with MongoDB and Node.js

Setup:

$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
// Send cookies for the socket.io handshake (sails.js)
// Based on https://gist.github.com/jfromaniello/4087861
// Socket.io open ticket (started by jfromaniello):
// https://github.com/LearnBoost/socket.io-client/pull/512
var io = require('socket.io-client');
var request = require('request');
var xhr = require('socket.io-client/node_modules/xmlhttprequest');
var xhrOriginal = require('xmlhttprequest');
/* Sample JavaScript file added with ScriptTag resource.
This sample file is meant to teach best practices.
Your app will load jQuery if it's not defined.
Your app will load jQuery if jQuery is defined but is too old, e.g. < 1.7.
Your app does not change the definition of $ or jQuery outside the app.
Example: if a Shopify theme uses jQuery 1.4.2, both of these statements run in the console will still return '1.4.2'
once the app is installed, even if the app uses jQuery 1.9.1:
jQuery.fn.jquery => "1.4.2"
$.fn.jquery -> "1.4.2"
*/