Skip to content

Instantly share code, notes, and snippets.

View frankpinto's full-sized avatar

Frank Pinto frankpinto

View GitHub Profile
@frankpinto
frankpinto / maybe_on.js
Created October 11, 2012 04:00
Conditional Synapse Embed
<script type="text/javascript">
var onswipeSometimes = function() {
var usr = "f";
var fractionToRedirect = '3/4';
var parts = fractionToRedirect.split('/');
var total = parseInt(parts[1]);
var redirect = parseInt(parts[0]);
var randomNumber = Math.floor(Math.random()*total + 1); // Number between 1 and total inclusive
if (randomNumber <= redirect) {
var synapse = 'http://assets.onswipe.com/synapse/on.js?usr=' + usr;
@frankpinto
frankpinto / redraw.js
Created October 25, 2012 02:49
This scope?
/*
* Receive the data from the server and draw what the other client sent
*/
// Get current PaperScope context
var newScope = (function(paper, socket) {
console.log(this);
paper.install(this);
var originalLayer;
@frankpinto
frankpinto / redraw.js
Created November 7, 2012 15:47
Receive drawing and draw it using PaperScript
/*
* Receive the data from the server and draw what the other client sent
*/
var socketedPaper = {};
document.addEventListener('paperReady', function() {
paper.install(socketedPaper);
socketedPaper.socket = socket;
//socketedPaper.projects[0].activate();
console.log('In redraw', socketedPaper);
@frankpinto
frankpinto / clear_cache.js
Created November 15, 2012 20:54
Remove fetchnow articles from cache
var mongo = require('onswipe-shared').mongo();
var redis = require('./lib/redis'); // From Synapse
if (process.argv.length > 2)
{
var entriesCollection = mongo.collection('entries');
pid = parseInt(process.argv[2]);
entriesCollection.find({publisher_id: pid, source_id: null}, function(err, entries) {
if (err) {
console.log(err);
@frankpinto
frankpinto / psql_wrapper.sh
Created July 18, 2014 17:22
Wrapper script used to run sql scripts across environments
#!/usr/bin/env bash
if [ $ENVIRONMENT = 'development' ]; then
psql ayalo_dev postgres < script.sql;
elif [ $ENVIRONMENT = 'beta' ]; then
PGPASSWORD=scrubbed psql -h scrubbed --port 5432 ayalo_dev postgres < script.sql
elif [ $ENVIRONMENT = 'production' ]; then
PGPASSWORD=scrubbed psql -h scrubbed --port 5492 scrubbed scrubbed < script.sql
fi
@frankpinto
frankpinto / bash.sls
Created April 29, 2015 23:59
file.line not working
/home/vagrant/.bashrc:
file.append:
- text:
- "set -o vi"
temp_cleanup:
file.line:
- name: /home/vagrant/.bashrc
- path: /home/vagrant/.bashrc
- content: "alias l='ls -liah'"
@frankpinto
frankpinto / setup_scraper_demo.sh
Created May 4, 2015 19:44
Demo de descargar varias paginas async
#!/usr/bin/env bash
# Requisito de usar este script es tener node.js instalado
command -v node >/dev/null 2>&1 || { echo >&2 "Se require Node.JS para ejecutar este script. Por favor instalelo (https://nodejs.org/) e ejecutelo de nuevo."; exit 1; }
# Crear demo directory
git clone https://github.com/frankpinto/scraper-demo.git
# Instalar dependencias
cd scraper-demo
@frankpinto
frankpinto / Rakefile
Last active August 29, 2015 14:22
Ruby s3 SDK example
task :fix_image_headers => :environment do
puts "---------------------------------------------"
puts "Uploading ad images to tools.ayalo.co"
puts "---------------------------------------------"
# Set s3 credentials
Dotenv.load
# Example of Client interface
s3 = Aws::S3::Client.new
@frankpinto
frankpinto / postgresql.sls
Created June 9, 2015 02:08
PostgreSQL salt file
"Remove broken precise PostgreSQL APT":
pkgrepo.absent:
- name: deb http://apt.postgresql.org/pub/repos/apt/ precise main
- dist: precise
- comps: main
"Remove precise PostgreSQL APT":
pkgrepo.absent:
- name: deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main
@frankpinto
frankpinto / test_helper.rb
Created September 3, 2015 22:13
Rails 4.2.4 test helper
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end