Skip to content

Instantly share code, notes, and snippets.

Shavit shavit

  • USA
View GitHub Profile
@shavit
shavit / random.sh
Created Dec 13, 2016
Random string in Unix
View random.sh
#!/bin/sh
cat /dev/urandom | envcd 'a-f0-9' | head -c 16
@shavit
shavit / router-pubsub.js
Created Dec 11, 2016
Publish subscribe with Javascript
View router-pubsub.js
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 Dec 2, 2016
Go UDP write receive example
View udp_client.go
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 / make_gif.sh
Created Nov 30, 2016
Create gif from video
View make_gif.sh
#!/bin/sh
ffmpeg -y -i video.mp4 meme.gif -f gif
@shavit
shavit / filters.md
Created Nov 18, 2016
Available filters on iOS 10
View filters.md

Core Image Filters on iOS 10

CIAccordionFoldTransition
CIAdditionCompositing
CIAffineClamp
CIAffineTile
CIAffineTransform
CIAreaAverage
CIAreaHistogram
@shavit
shavit / broadcast_udp.swift
Created Nov 14, 2016
Send a message using UDP in Swift 3
View broadcast_udp.swift
//: 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 Oct 25, 2016
Print new output on the same line with python 3
View carriage_return.py
#
# 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 Oct 14, 2016
Broadcast to server and stream binary files with python
View client.py
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 / concurrency.go
Created Sep 21, 2016
Concurrency example in Go
View concurrency.go
package main
import (
"log"
"time"
"sync"
)
// Loop 10 times, print every 1 second
func One(){
@shavit
shavit / user.ex
Created Sep 21, 2016
Update user without password in Elixir Phoenix with Guardian plug
View user.ex
#
# 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
You can’t perform that action at this time.