Skip to content

Instantly share code, notes, and snippets.

View RohitRox's full-sized avatar
🎯
Focusing

Rohit Joshi RohitRox

🎯
Focusing
View GitHub Profile
@RohitRox
RohitRox / python_bash
Created July 20, 2013 09:54
python , postgres and ubuntu
# pip and virtualenv are installed upto here
# cd to python one directory before project folder
virtualenv ENV
source envnmnt/bin/activate
cd project
pip install -r requirements.txt
./manage.py syncdb
./manage.py migrate
./manage.py runserver
# Only for Mac OS X, where .bashrc is otherwise ignored
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
# MacPorts
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH

Install Python

$ brew install readline sqlite gdbm
$ brew install python --universal --framework
$ python --version
Python 2.7

Symlinks...

@RohitRox
RohitRox / amazon_stuffs.md
Last active December 20, 2015 12:09
Save an image file directly to S3 from a web browser using HTML5

You need to create a CORS configuration manifest, for the bucket you wish to grant access to. Amongst other things, the manifest indicates:

  • what domains are allowed to access the S3 bucket.
  • the actions that can be taken (PUT, POST, GET, DELETE) To create the manifest:
  • choose the S3 option from your AWS Management Console.
  • On the bucket you wish to grant CORS access to, click the properties option.
  • note the option, Edit CORS Configuration I created a configuration that looks something like this:
# .irbrc to log goodies like SQL/Mongo queries to $stdout if in Rails 3 console
if defined?(Rails) && Rails.respond_to?(:logger)
require 'logger'
Rails.logger = Logger.new($stdout)
if defined?(Mongoid)
Mongoid.logger = Rails.logger
end
end
@RohitRox
RohitRox / colorize.rb
Created August 27, 2013 11:34
Colorize terminal outputs in Ruby
class String
def black; "\033[30m#{self}\033[0m" end
def red; "\033[31m#{self}\033[0m" end
def green; "\033[32m#{self}\033[0m" end
def brown; "\033[33m#{self}\033[0m" end
def blue; "\033[34m#{self}\033[0m" end
def magenta; "\033[35m#{self}\033[0m" end
def cyan; "\033[36m#{self}\033[0m" end
def gray; "\033[37m#{self}\033[0m" end
def bg_black; "\033[40m#{self}\0330m" end
@RohitRox
RohitRox / not_in_query.rb
Created September 10, 2013 08:48
Rails 3 Active Record NOT / NOT IN
User.where(["active = 1 AND id NOT IN (?)", [3,9]])
@RohitRox
RohitRox / mysql2_mysqlh_missing_fix
Created September 12, 2013 08:13
gem install mysql2 missing mysql.h on Mountain Lion
edit the /usr/local/Cellar/mysql/5.6.12/bin/mysql_config
The original:
cflags="-I$pkgincludedir -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
cxxflags="-I$pkgincludedir -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
the changed version:
cflags="-I$pkgincludedir -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
cxxflags="-I$pkgincludedir -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF -arch x86_64 " #note: end space!
.pagination a, .pagination span.current, .pagination span.gap {
float: left;
padding: 0 14px;
line-height: 38px;
text-decoration: none;
background-color: white;
border: 1px solid #DDD;
border-left-width: 0;
}
@RohitRox
RohitRox / rails_quick_tips.md
Created October 4, 2013 05:31
Rails Quick Tips

Rails destroy all but not in

  Foo.destroy_all(['id NOT IN (?)', newest_n_records.collect(&:id)])
  # or
  Foo.destroy_all('created_at < ?', newest_n_records.last.created_at)