Skip to content

Instantly share code, notes, and snippets.

View cr0t's full-sized avatar
🏠
Working from home

Sergey Kuznetsov cr0t

🏠
Working from home
View GitHub Profile
@cr0t
cr0t / nginx images rewrite
Created November 15, 2010 19:52
Nginx location rewrite rules for some special sort of images. For example, we need to send /var/www/domain/object-images/997/100x74/9979998.jpg file for the query URI like: http://example.com/object-images/997/100x74/9979998/MacBook-Pro-13-inches.jpg
location ~ ^.+\.(jpe?g|gif|png)$ {
rewrite ^(/object-images)/(\d+)/([0-9x]+)/(\d+)/([a-zA-Z0-9-]+).jpg$ $1/$2/$3/$4.jpg last;
try_files $uri /images/empty.png;
access_log off;
expires 3h;
}
/**
* Upload action (for partial - AJAX uploads)
* Works with chunks of uploading files, save them to HDFS directly
*/
def ajax() = {
response.setHeader("Access-Control-Allow-Origin", "*")
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
response.setHeader("Access-Control-Allow-Headers", "X-Requested-With,X-File-Name,Content-Type")
response.setHeader("Access-Control-Max-Age", "1728000")
@cr0t
cr0t / App.scala
Created August 31, 2011 15:02 — forked from teamon/App.scala
import Benchmark._
object App {
def main(args: Array[String]): Unit = {
benchmark(100000){
report("foo"){ foo() } ::
report("bar"){ bar() } ::
Nil
}
}
@cr0t
cr0t / gist:1243431
Created September 26, 2011 21:20
Play! framework: How do get files from Hadoop and send them via HTTP
object Download extends Controller {
import org.apache.commons.logging.Log
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs._
import java.io.InputStream
import java.net.URI
import java.net.URLDecoder
def download(filename: String) = {
@cr0t
cr0t / osx_lion_rail_setup.md
Created December 23, 2011 16:39 — forked from jpantuso/osx_lion_rail_setup.md
Setup OS X 10.7 w/ homebrew, oh-my-zsh, rvm, rails, and MySQL
@cr0t
cr0t / gist:1826732
Created February 14, 2012 13:24
unicorn.rb config file
APP_PATH = "/var/www/tld.appname"
rails_env = ENV["RAILS_ENV"] || "development"
# 2 workers and 1 master
worker_processes 2
working_directory APP_PATH + "/current" # available in 0.94.0+
# Load rails+github.git into the master before forking workers
@cr0t
cr0t / gist:1826746
Created February 14, 2012 13:26
unicorn init script
#!/bin/sh
# we assume that we use system wide rvm installation (in /usr/local/rvm)
# and our application is deployed to /var/www/tld.appname directory
RVM_ENV="ruby-1.9.3-p0@gemset"
APP_DIR="tld.appname"
# load rvm
source /usr/local/rvm/environments/$RVM_ENV
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
.DS_Store
# Ignore bundler config.
/.bundle