Skip to content

Instantly share code, notes, and snippets.

View rusllonrails's full-sized avatar
💭
👨‍💻 💻 🖱️ 🍻 🏋️‍♂️

rusllonrails rusllonrails

💭
👨‍💻 💻 🖱️ 🍻 🏋️‍♂️
  • Tbilisi, Georgia
View GitHub Profile
@rusllonrails
rusllonrails / gist:9016770
Created February 15, 2014 09:36
JAVASCRIPT ROUND UP
app.round_up = (float, digits) ->
digits = (if not digits? then 2 else digits)
k = Math.pow(10, digits)
int = (float * k).toFixed(1)
rounded = Math.floor(int)
((rounded + ((if int - rounded < 0.5 then 0 else 1))) / k).toFixed 2
@rusllonrails
rusllonrails / POSTGRES CHANGE COLUMN TYPE
Last active August 29, 2015 13:56
POSTGRES CHANGE COLUMN TYPE
class ChangeMessages < ActiveRecord::Migration
def change
rename_column :messages, :recipient_ids, :old_recipient_ids
add_column :messages, :recipient_ids, :integer, array: true
Message.all.each do |message|
message.recipient_ids = message.old_recipient_ids
message.save!(validate: false)
end
@rusllonrails
rusllonrails / COFFEE SCRIPT PLURALIZE
Created February 18, 2014 10:17
COFFEE SCRIPT PLURALIZE
app.pluralize = (num, variant1, variant2, variant3)->
plural =
if num % 10 == 1 && num % 100 != 11
0
else if num % 10 >= 2 && num % 10 <= 4 && (num % 100 < 10 || num % 100 >= 20)
1
else
2
switch plural
@rusllonrails
rusllonrails / UBUNTU JAVA INSTALL
Created March 15, 2014 16:30
UBUNTU JAVA INSTALL
1) Enter these 2 commands in the Terminal to add this PPA and update your packages list:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
2) Enter one (or more) of these commands to install the proprietary Java(s) you require:
sudo apt-get install oracle-java6-installer
sudo apt-get install oracle-java7-installer
sudo apt-get install oracle-java8-installer
@rusllonrails
rusllonrails / ORDER BY IDS SEQUENCE
Created March 31, 2014 06:53
ORDER BY IDS SEQUENCE
1. Mysql only
> ids = [11,31,29]
=> [11, 31, 29]
> Page.where(id: ids).order("field(id, #{ids.join(',')})")
2. Postrgesql variant
def self.order_by_ids(ids)
order_by = ["case"]
@rusllonrails
rusllonrails / Run unicorn as daemon
Created March 31, 2014 13:15
Run unicorn as daemon
bundle exec unicorn_rails -c config/unicorn.conf.rb -E production -D
@rusllonrails
rusllonrails / Rspec cover class
Created April 1, 2014 18:05
Rspec cover class
lib/tasks/dummy.rake
namespace :db do
desc "Add system data"
task dummy: :environment do
SeedDummyData.run
end
end
class SeedDummyData
@rusllonrails
rusllonrails / SUBLIME TEXT 3 install copy files plugin
Created April 5, 2014 06:07
SUBLIME TEXT 3 install copy files plugin
CTRL + SHIFT + P
in opened window put: Install
ENTER
in opened window put: SidebarFileExt
ENTER
@rusllonrails
rusllonrails / VI commands
Created April 9, 2014 17:32
VI commands
For editing use
vi galfit.feedme
For inserting
Press i //Do required editing
@rusllonrails
rusllonrails / Vagrant full uninstall
Created April 17, 2014 11:27
Vagrant full uninstall
sudo apt-get remove --auto-remove vagrant
sudo apt-get purge --auto-remove vagrant
sudo rm -rf /opt/vagrant
sudo rm -rf /usr/bin/vagrant
sudo rm -rf ~/.vagrant.d