Skip to content

Instantly share code, notes, and snippets.

/* 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"
*/
// 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');

Pub/sub with MongoDB and Node.js

Setup:

$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
@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}"
@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
/* 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"
*/
#!/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
@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);
}
@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 / applescript_launch_command_on_idle.txt
Created February 1, 2018 16:51
AppleScript - Launch command if computer has been idle for X seconds
property idleTest : 180 -- How long to be idle (in seconds) before activating script
on idle_time()
set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,\"\";last}'")
return idleTime
end idle_time
script should_run_matrix
set idleComp to false
-- this repeat loop polls the idle time every 30 seconds to determine