Skip to content

Instantly share code, notes, and snippets.

View fiftin's full-sized avatar

Denis Gukov fiftin

View GitHub Profile
@fiftin
fiftin / bestTick.js
Created December 27, 2016 03:19
Best ticks for Y axis
function bestTick(largest, mostticks) {
var minimum = largest / mostticks;
var magnitude = Math.pow(10, Math.floor(Math.log(minimum) / Math.log(10)));
var residual = minimum / magnitude;
var tick;
if (residual > 5) {
tick = 10 * magnitude;
} else if (residual > 2) {
tick = 5 * magnitude;
} else if (residual > 1) {
@fiftin
fiftin / numDigits.js
Created December 27, 2016 03:17
Number of digits
function numDigits(x) {
return (Math.log10((x ^ (x >> 31)) - (x >> 31)) | 0) + 1;
}
@fiftin
fiftin / count.sql
Last active November 22, 2016 07:25
Count the number of occurrences of a char in MySQL
UPDATE Entities SET depth = (LENGTH(path) - LENGTH(REPLACE(path, '/', ''))) + 2 WHERE path <> '';
@fiftin
fiftin / Convert PostgreSQL to SQLite
Created October 5, 2015 07:04
Convert PostgreSQL to SQLite
1. Dump the data only sql to file
$ pg_dump --data-only --inserts YOUR_DB_NAME > dump.sql
2. scp to local
3. Remove the SET statements at the top
such as:
SET statement_timeout = 0;
SET client_encoding = 'SQL_ASCII';
4. Remove the setval sequence queries
@fiftin
fiftin / psql2sqlite.sed
Last active October 5, 2015 08:27 — forked from HGebhardt/psql2sqlite.sed
Convert PostgreSQL data to SQLite
#! /bin/sed -f
# add begin transaction
1s/^SET .*$/END;\nBEGIN;\n/
1s/^-- .*$/END;\nBEGIN;\n/
1s/^/BEGIN;\n/
# remove configuration settings
/^SET /d
@fiftin
fiftin / add_background_to_spree_taxon.rb
Created September 14, 2015 04:11
Add image to model the example of Spree taxon model
class AddBackgroundToSpreeTaxons < ActiveRecord::Migration
def change
add_column :spree_taxons, :background_file_name, :string
add_column :spree_taxons, :background_content_type, :string
add_column :spree_taxons, :background_file_size, :integer
add_column :spree_taxons, :background_updated_at, :timestamp
end
end
@fiftin
fiftin / README.md
Last active October 20, 2016 10:29
Spree Commerce: Russian Ruble Symbol

If you want use Russian Ruble currency in Spree Commerce you should add this monay.rb to config/initializer directory of your project.

@fiftin
fiftin / 0_example.rb
Last active September 13, 2015 18:44 — forked from radar/0_example.rb
Order.class_eval do
checkout_flow do
go_to_state :address
go_to_state :delivery
go_to_state :payment, :if => lambda { payment_required? }
go_to_state :confirm, :if => lambda { confirmation_required? }
go_to_state :complete
remove_transition :from => :delivery, :to => :confirm
end
end
@fiftin
fiftin / README.md
Last active September 13, 2015 18:47
Spree Commerce: Order confirmation require

If you wont confirmation page on the finish Spree checkout flow you need override confirmation_required? as in example.

@fiftin
fiftin / checkout_controller_decorator.rb
Created September 13, 2015 18:25
Spree Commerce: Skip delivery checkout step
Spree::CheckoutController.class_eval do
def before_delivery
@order.next
redirect_to checkout_state_path(@order.state)
end
end