Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / go-revel.service
Created April 25, 2017 04:05
Go Revel Systemd script
[Unit]
Description=API web app
[Service]
PIDFile=/tmp/app.pid-0000
User=
Group=
WorkingDirectory=
ExecStart=PATH-TO-APP/bin/app/start.sh
@shavit
shavit / index.html
Created June 1, 2017 17:51
Preload images on a webpage
<html>
<img src="" hide>
</html>