Skip to content

Instantly share code, notes, and snippets.

@shavit
shavit / create_swarm.sh
Created August 15, 2017 01:25
Create swarm of Docker servers
#!/bin/sh
#
# Create a swarm manager and consul
#
# 1. Create 7 servers
# CONSUL_ADDRESS=
# SWARM_MANAGER_1_ADDRESS=
# SWARM_MANAGER_2_ADDRESS=
# LOAD_BALANCER_1_ADDRESS=
@shavit
shavit / generate_crt.sh
Created August 1, 2017 18:11
Create protobuf server with go
openssl genrsa -out server.key 2048
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 365
@shavit
shavit / index.html
Created June 1, 2017 17:51
Preload images on a webpage
<html>
<img src="" hide>
</html>
@shavit
shavit / facebook_apps_controller.rb
Created March 15, 2013 16:32
Facebook page and canvas apps with Rails 4, can lead to a blank white page. In Rails 4, the X-Frame-Options are sets by default, and you should override them, to allow iframes in Rails.
class FacebookClubsController < ApplicationController
layout "facebook_canvas"
after_filter :allow_iframe
def index
end
private
@shavit
shavit / nginx-server.conf
Created March 12, 2017 18:10
Nginx configuration file for undefined requests
# Block access from IP
server {
listen 80 default;
server_name _;
ssl off;
# No response
return 444;
}
@shavit
shavit / facebook.coffee
Created February 28, 2013 11:01
Facebook JavaScript SDK in CoffeeScript
#
# You should add the Facebook App ID and the channel url (optional), in the #fb-root element, as a data- attribute:
# <div id="fb-root" data-app-id="<%= ENV['FACEBOOK_APP_ID'] %>" data-channel-url="<%= url_no_scheme('/channel.html') %>"></div>
#
window.fbAsyncInit = ->
FB.init
appId: document.getElementById("fb-root").getAttribute("data-app-id")
channelUrl: document.getElementById("fb-root").getAttribute("data-channel-url")
status: true,
cookie: true,
@shavit
shavit / free_space.sh
Created December 19, 2016 04:03
Find free space on Mac
#!/bin/sh
sudo perl -e'%h=map{/.\s/;99**(ord$&&7)-$`,$_}`du -h`;die@h{sort%h}'
@shavit
shavit / random.sh
Created December 13, 2016 23:18
Random string in Unix
#!/bin/sh
cat /dev/urandom | envcd 'a-f0-9' | head -c 16
@shavit
shavit / router-pubsub.js
Created December 11, 2016 20:49
Publish subscribe with Javascript
class Router {
constructor(){
const path = (window.location.href.split("/#!")[1])
?(window.location.href.split("/#!")[1])
:(window.location.href.split(/src\/html/)[1])
// callbacks
this.actions = []
this.state = {
baseURL: window.location.protocol+"://"+window.location.host,
path: path,
@shavit
shavit / udp_client.go
Created December 2, 2016 00:47
Go UDP write receive example
package main
import (
"net"
)
func main(){
message := []byte("Hello world")
localAddress, _ := net.ResolveUDPAddr("udp", "127.0.0.1:0")
remoteAddress, _ := net.ResolveUDPAddr("udp", "127.0.0.1:1936")