# serve all assets from CDN server
config.action_controller.asset_host = 'http://cdn.mydomain.com'
#or if your files in a folder on CDN server
config.action_controller.asset_host = 'http://cdn.mydomain.com/myfolder'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file libs/dbutil.py | |
from itertools import * | |
from django.db import connection | |
def query_to_dicts(query_string, *query_args): | |
cursor = connection.cursor() | |
cursor.execute(query_string, query_args) | |
col_names = [desc[0] for desc in cursor.description] | |
while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import connection, transaction | |
cursor = connection.cursor() | |
cursor.execute("UPDATE yourtablename SET field1=value1, .. WHERE .. ") | |
transaction.set_dirty() | |
transaction.commit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def resize_nocrop_noscale(image, w,h) | |
w_original = image[:width].to_f | |
h_original = image[:height].to_f | |
if w_original < w && h_original < h | |
return image | |
end | |
# resize | |
image.resize("#{w}x#{h}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mysql2' | |
db = Mysql2::Client.new(:host => 'localhost', :username => 'root', :password=> 'password', :database => 'db_name' ) | |
res = db.query("select * from users") | |
res.each do |row| | |
col1 = row['id'] | |
col2 = row['email'] | |
.. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in controller | |
# for local files | |
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment' | |
# for remote files | |
require 'open-uri' | |
url = 'http://someserver.com/path/../filename.jpg' | |
data = open(url).read | |
send_data data, :disposition => 'attachment', :filename=>"photo.jpg" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. connection.select_values or connection.select_all | |
ids = ActiveRecord::Base.connection.select_values("select id from users WHERE ...") | |
# array of integers | |
# ["1", "2", "5", "6", "7", "8", "3", "10", "11", "9"] | |
# return hashes without model | |
sql = "sql query" | |
rows = User.connection.select_all(sql.squish!) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. connection.select_values or connection.select_all | |
ids = ActiveRecord::Base.connection.select_values("select id from users WHERE ...") | |
# array of integers | |
# ["1", "2", "5", "6", "7", "8", "3", "10", "11", "9"] | |
# return hashes without model | |
sql = "sql query" | |
rows = User.connection.select_all(sql.squish!) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# put in /etc/munin/plugins and restart munin-node | |
# by Dan Manges, http://www.dcmanges.com/blog/rails-application-visualization-with-munin | |
# NOTE: you might need to add munin to allow passwordless sudo for passenger-memory-stats | |
def output_config | |
puts <<-END | |
graph_category App | |
graph_title Passenger memory stats | |
graph_vlabel count |
OlderNewer