Skip to content

Instantly share code, notes, and snippets.

@smsohan
smsohan / production.rb
Last active December 22, 2015 00:59
production.rb
#put all the shared bits in: config/environments/productionable.rb
YourApp::Application.configure do
config.assets.compile = false
config.serve_static_assets = false
end
@smsohan
smsohan / MemoryStreamResourceProvider.cs
Last active December 21, 2015 07:19
LinkedResource using a Stream instead of a file path on disc
public class StreamResourceProvider : LinkedResourceProvider{
/// <summary>
/// Gets a linked resource given its Id and FilePath
/// </summary>
public override LinkedResource Get(string contentId, string filePath){
var stream = GetYourStream(contentId, filePath);
return new LinkedResource(stream);
}
private Stream GetYourStream(contentId, filePath){
@smsohan
smsohan / export_controller.rb
Created March 20, 2013 21:26
Stream CSV data in Rails 3.2
class ExportController < ApplicationController
def index
#suitable for streaming data, no caching http://wiki.nginx.org/X-accel#X-Accel-Buffering
headers['X-Accel-Buffering'] = 'no'
headers["Cache-Control"] ||= "no-cache"
headers.delete("Content-Length")
headers["Content-Type"] = "text/csv"
headers["Content-disposition"] = 'attachment; filename="gaga.csv"'
@smsohan
smsohan / build.sh
Created February 27, 2013 16:16
A Rake Task to precompile the assets and then make a tarball of the rails project for deploys.
#clean up the existing files
rm -rf pkg tmp/cache public/assets
bundle exec rake build_package
@smsohan
smsohan / regex.txt
Created February 1, 2013 20:52
Regular expression to replace url("/images/hello.png") with url(<%= asset_path 'hello.png' %>) used for Rails 3.2 upgrade to use asset pipeline
url\("*\s*\/images\/([^"^)]*)"*\s*\)
url(<%= asset_path '\1' %>)
@smsohan
smsohan / deploy.sh
Created July 28, 2012 19:23
shell example of rails capistrano deploy
$ ls -al /app/realtime/releases
current --> 20120729083021
20120722101234
20120603134509
@smsohan
smsohan / example_controller.rb
Created July 28, 2012 19:02
Example controller with server token
class ExampleController < ApiController
def index
data = Sale.realtime_data
#get the timestamp of this deployment
server_token = File.basename(Rails.root.to_s)
respond_with(data: data, server_token: server_token)
end
@smsohan
smsohan / api_module.js
Created July 28, 2012 18:58
Sample API module
apiModule = {
get: function(url, callback, errorCallback) {
return $.ajax({
url: url,
success: function(response) {
if(isNewServerToken(response.server_token)){
reloadPage();
}
else{
@smsohan
smsohan / example_controller.rb
Created July 28, 2012 18:38
Example controller with server token
class ExampleController < ApplicationController
def index
data = Sale.example_data
server_token = Rails.root.to_s
respond_with {data: data, server_token: server_token}
end
end
@smsohan
smsohan / api_module.js
Created July 28, 2012 18:15
Common module for all API calls
apiModule = {
get: function(url, callback, errorCallback) {
return $.ajax({
url: url,
success: function(response) {
if(isNewServerToken(response.serverToken)){
reloadPage()
}
else{