Skip to content

Instantly share code, notes, and snippets.

View fiftin's full-sized avatar

Denis Gukov fiftin

View GitHub Profile
@fiftin
fiftin / mysql2sqlite.sh
Created October 2, 2011 19:43 — forked from esperlu/mysql2sqlite.sh
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@fiftin
fiftin / HttpUploadImageTask.java
Last active September 13, 2015 18:21
Async uploading an image as file to the server from Android application
private class HttpUploadImageTask extends AsyncTask<String, Void, Boolean> {
final Bitmap imageBitmap;
public HttpUploadImageTask(final Bitmap imageBitmap) {
this.imageBitmap = imageBitmap;
}
@Override
protected Boolean doInBackground(String... urls) {
for (final String u : urls) {
try {
@fiftin
fiftin / long_word_wrap.rb
Last active December 3, 2015 08:30
Long word wrap with using Ruby on Rails
def long_word_wrap(str, options = {})
opts = { length: 10000, word_length: 10, shy_length: 4 }.merge(options)
ret = ''
offset = 0
str = truncate(str, length: opts[:length]) if str.length > opts[:length]
m = str.match(/[^\s\n\r]{#{opts[:word_length]},}/, offset)
while m
ret << h(str[offset..m.begin(0)-1]) if offset < m.begin(0)
s = m[0].scan(/[^\s\n\r]{1,#{opts[:shy_length]}}/)
ret << s.map{ |x| h(x) }.join('&shy;')
@fiftin
fiftin / remove_admin_bar.php
Last active September 4, 2015 03:17
Plugin for removing admin bar from Webpress site
<?php
/*
Plugin Name: Remove admin bar
Author: Denis Gukov
Version: 1.0
*/
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
@fiftin
fiftin / wc2bs-patcher.php
Last active September 10, 2015 08:40
Peplace "button" class in the WooCommerce templates to "btn btn-default" class. Useful if you can use Bootstrap Theme.
<?php
function ends_with($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
@fiftin
fiftin / address_decorator.rb
Last active September 13, 2015 18:22 — forked from rozhok/address_decorator.rb
Remove billing address from Spree checkout page
Deface::Override.new(:name => "remove billing address form",
:virtual_path => "spree/checkout/_address",
:remove => "#billing[data-hook]"
)
Deface::Override.new(:name => "remove use billing address checkbox",
:virtual_path => "spree/checkout/_address",
:remove => "[data-hook='use_billing']"
)
@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
@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 / 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 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.