Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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 / 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"
)
@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 / 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__))