Skip to content

Instantly share code, notes, and snippets.

@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")
@shavit
shavit / filters.md
Created November 18, 2016 03:25
Available filters on iOS 10

Core Image Filters on iOS 10

CIAccordionFoldTransition
CIAdditionCompositing
CIAffineClamp
CIAffineTile
CIAffineTransform
CIAreaAverage
CIAreaHistogram
@shavit
shavit / broadcast_udp.swift
Created November 14, 2016 03:03
Send a message using UDP in Swift 3
//: Playground - noun: a place where people can play
import Cocoa
import Darwin
func htons(value: CUnsignedShort) -> CUnsignedShort {
return (value << 8) + (value >> 8)
}
let INADDR_ANY = in_addr(s_addr: 0)
@shavit
shavit / carriage_return.py
Created October 25, 2016 17:54
Print new output on the same line with python 3
#
# Print in one line dynamically
#
from sys import stdout
from time import sleep
def progress():
for i in range(0,100):
stdout.write('\rLoading {}%'.format(i+1))
stdout.flush()
@shavit
shavit / client.py
Created October 14, 2016 07:44
Broadcast to server and stream binary files with python
import os
import socket
videos = []
client = socket.socket()
client.connect((socket.gethostbyname('localhost'), 3000))
# Append the video files paths into array
def load_videos():
base_dir = os.path.dirname(os.path.realpath(__file__))
@shavit
shavit / user.ex
Created September 21, 2016 02:36
Update user without password in Elixir Phoenix with Guardian plug
#
# web/models/user.ex
#
defmodule Plans.User do
use Plans.Web, :model
@primary_key {:id, :binary_id, autogenerate: true}
schema "users" do
field :username, :string
field :email, :string
@shavit
shavit / custom_template_functions.go
Created September 20, 2016 16:23
Create custom helpers for HTML and XML templates in Go
content, err = ioutil.ReadFile("templates/rss.xml")
if err != nil {
panic(err)
}
//Custom template helpers
fm := template.FuncMap{"number": func(n int) string {
return strconv.Itoa(n)
}, "float": func(f float64) string {
return strconv.FormatFloat(f, 'f', -1, 64)
@shavit
shavit / haiku.ex
Created September 20, 2016 03:47 — forked from friggeri/haiku
random heroku-like name generator in Elixir
def generate_name do
# [[64][64]]
[["autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark",
"summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter",
"patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue",
"billowing", "broken", "cold", "damp", "falling", "frosty", "green",
"long", "late", "lingering", "bold", "little", "morning", "muddy", "old",
"red", "rough", "still", "small", "sparkling", "throbbing", "shy",
"wandering", "withered", "wild", "black", "young", "holy", "solitary",
"fragrant", "aged", "snowy", "proud", "floral", "restless", "divine",
@shavit
shavit / worker_mongodb_queue.go
Created September 3, 2016 14:24
Go worker with MongoDB capped collection
package main
import (
"os"
"log"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"time"
)