Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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,