Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / CreateCappedCollection.js
Created September 2, 2016 19:26
Create a tailable MongoDB capped collection
db.createCollection("jobs", {
capped: 1,
size: 100000,
max: 10
})
@shavit
shavit / search.sql
Last active July 29, 2016 04:44
Full text search for WordPress with MySQL
SELECT
ID,
post_title,
post_status,
CONCAT('http://www.yourwebsite.com/wp-content/uploads/',
thumbnail.meta_value) AS picture,
MATCH (post_title) AGAINST ('term') AS title_score,
MATCH (post_excerpt) AGAINST ('term') AS excerpt_score,
MATCH (post_content) AGAINST ('term') AS content_score
FROM wp_posts
@shavit
shavit / recommended_posts.sql
Created July 28, 2016 21:25
Recommended posts example in PostgreSQL using full text search, based on a single post
@shavit
shavit / post-receive
Created July 6, 2016 21:57
Deploy meteor app on Ubuntu
#!/bin/sh
#
# On your local machine
#
# local$ npm install --production
# local$ meteor build .build --architecture os.linux.x86_64
#
# On your server
@shavit
shavit / server-power.sh
Last active June 25, 2016 00:53
Optimize Nginx and workers
# workers
# grep processor /proc/cpuinfo | wc -l
#
# workers connections
# ulimit -n
# Check the architecture
grep --color=always -iw lm /proc/cpuinfo
# Buid go workers