Skip to content

Instantly share code, notes, and snippets.

View costa's full-sized avatar

Costa Shapiro costa

View GitHub Profile
@costa
costa / pusher.js.coffee
Created November 25, 2014 11:08
Client-side asynchronous pusher init utility: app/assets/javascripts
window.pusher_async = (pusher_or_key, callback)->
return _(pusher_async).delay 22, key unless Pusher?
callback if typeof pusher_or_key is 'string' then new Pusher pusher_or_key else pusher_or_key
@costa
costa / notification.rb
Last active August 29, 2015 14:10
Rails model notification concern employing Pusher: app/models/concerns
module Notification
extend ActiveSupport::Concern
included do
after_create { notify 'created' }
after_update { notify 'updated' }
after_destroy { notify 'destroyed' }
class << self
@costa
costa / _client_.coffee
Last active August 29, 2015 14:10
Rails: asynchronous pusher clientside initialisation snippet
# ... somewhere in your Backbone app init function, after initialising the "@things" collection:
pusher_async pusher_or_key, (pusher)=>
pusher.connection.bind 'connected', => @things.fetch()
new Backpusher pusher.subscribe(channel), @things
# ... where channel's value is being rendered in the caller template like this:
"#{ENV['FAKE_PUSHER']? PusherFake.javascript : Pusher.key.to_json}"
@costa
costa / _application_.html.haml
Last active August 29, 2015 14:10
Rails: loading asynchronous Pusher client-side (js) module: in app/views/layouts/application.html.haml
- if defined? PusherFake
= javascript_tag File.read Dir.glob(File.expand_path 'features/support/application/public/javascripts/vendor/pusher-2.*.js', Bundler.load.specs.find{|s| s.name == 'pusher-fake' }.full_gem_path).last
- else # NOTE Since Pusher is not really useful with no internet connection... let's CDN it
%script{:src => "http://js.pusher.com/2.0/pusher.min.js", :defer => true}
@costa
costa / mock_firebase.js.coffee
Created February 4, 2015 20:52
MockFirebase persistence shim; to be used with e.g. `window.MOCK_FIREBASE = #{{"null/things/#{id}" => firebase_val}.to_json};`
#= require mockfirebase/browser/mockfirebase
MockFirebase.override()
class TrueMockFirebase extends Firebase
constructor: (path)->
super
_(=>
if window.MOCK_FIREBASE && MOCK_FIREBASE[path]
@set(MOCK_FIREBASE[path])
@costa
costa / docker-init.sh
Last active April 6, 2016 11:32
.dockerrc-enabling bash init
# NOTE source this file from $HOME/.bashrc
# NOTE and have a .dockerrc — e.g. containing "eval $(docker-machine env default)" — in your project directory
_before_dmm_docker() { command docker "$@"; }
OLD_DOCKER_FUNC="`declare -f docker`"
if [ -n "$OLD_DOCKER_FUNC" ]
then eval "_before_dmm_$OLD_DOCKER_FUNC"
fi
docker() {
local OLD_IFS="$IFS"
@costa
costa / exp.js
Created August 14, 2016 16:02
different event behaviour comparison
'use strict';
/* eslint-disable no-console */
var TEST_DELAY = 0;
var TEST_SIZE = 1000;
console.log('TO-Starting ' + TEST_SIZE);
var tos = Array.apply(null, Array(TEST_SIZE)).map(function startTimeout() {
return setTimeout(function stopAllTimeouts() {
try {
console.log('TO-Stopping ' + tos.length);
@costa
costa / files-excerpt.gemspec
Created August 26, 2016 12:18
better (.gemignore-based) gem spec.files globbing for build (not depending on git)
def self.ignore_match(pattern, path)
path = '/' + path unless path =~ %r'^/'
if File.directory?(path)
path += '/' unless path =~ %r'/$'
end
if pattern.is_a?(Array)
pattern
else
[pattern]
end.any? do |pattern|
@costa
costa / docker-dev.sh
Last active March 9, 2020 00:33
simple docker-machine-based dev helper
dev() {
local machine_name
local dir_name
local proj_name
local host
local host_user
local host_path
local ssh_cmd
if ! dev-setup
then return $?
@costa
costa / gcloud-machine-sendgrid-mail-setup.sh
Last active March 8, 2018 15:32
docker-machine ssh some-gcloud-machine 'curl <THIS-GIST-RAW-URL> | sudo sh'
echo "postfix postfix/mailname string ido-dev.bandmanage.com" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y postfix libsasl2-modules || exit 2
grep -vE 'default_transport = error|relay_transport = error' /etc/postfix/main.cf > /tmp/main.cf
cat /tmp/main.cf > /etc/postfix/main.cf
echo '
relayhost = [smtp.sendgrid.net]:2525
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes