Skip to content

Instantly share code, notes, and snippets.

@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
@shavit
shavit / post-receive
Created March 9, 2016 02:15
Ruby on Rails post receive file for Git deployments.
#!/bin/sh
APP_PATH=$APP_ROOT
exit_with_error(){
echo "---> An Error Has Occurred!"
}
echo "---> Receiving push as $USER"
git --work-tree=$APP_PATH --git-dir=$GIT_DIR checkout -f
@shavit
shavit / mass_video_importer_1.rb
Created January 14, 2016 16:37
Mass video importer from *.csv files to tube sites.
#
# Import videos from CSV
#
# CSV row:
# 0 - embedded_video
# 1 - link
# 2 - categories (Funny;Euro;Cam)
# 3 - rating
# 4 - author username
@shavit
shavit / go-revel-app.conf
Created January 11, 2016 14:44
Run Go Revel app in production as a service
start on runlevel [2345]
stop on runlevel [!2345]
respawn
env PORT=<APP-PORT>
setuid <APP-NAME>
chdir /<APP-PATH>
@shavit
shavit / post-receive
Created January 11, 2016 14:41
Git deployment for Go Revel application
#!/bin/sh
# /<REPOS-PATH>/<REPO-NAME>.git/hooks/post-receive
APP_PATH=/<APP-PATH>
exit_with_error(){
echo "---> An Error Has Occurred!"
}
echo "---> Receiving push as $USER"
git --work-tree=/<APP-PATH> --git-dir=/<REPOS-PATH>/<REPO-NAME>.git checkout -f
@shavit
shavit / install.sh
Created August 20, 2015 05:30
Compile Nginx with ramp module
./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/share/nginx/nginx-1.7.12 \
--add-module=../nginx-rtmp-module-master \
--sbin-path=/usr/local/sbin/nginx \
--conf-path=/usr/share/nginx/nginx-1.7.12/conf/nginx.conf \
--pid-path=/var/run/nginx.pid \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/varlog/nginx/access.log