Skip to content

Instantly share code, notes, and snippets.

class ParamsSlicer
def initialize(params, *whitelist)
@params = params
@nested_whitelist = whitelist.extract_options!
@whitelist = whitelist
end
def call
params.slice(*whitelist).tap do |result|
nested_whitelist.each do |k, v|
@gvozdb
gvozdb / msDiscountFromCost.php
Last active July 12, 2021 11:53
[MODX Revo] Разные скидки для miniShop2 в зависимости от общей суммы корзины
<?php
$chunk = 'tpl.msdfcMsg';
$discounts = array(
'100000' => '10%',
'150000' => '15%',
'200000' => '20%',
);
krsort($discounts);
reset($discounts);
$actionKey = 'msdfc_action';
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@gvozdb
gvozdb / packages.php
Last active April 4, 2023 08:28
Скрипт автоустановки компонентов в MODX. Работает как из консоли, так и из веба. Скрипт из консоли работает корректно на сервере, настроенном по этой инструкции - https://modx.pro/hosting/678-the-right-hosting-for-modx-revolution-2/
<?php
/*
Скрипт надо запускать от юзера - владельца сайта, чтобы созданные файлы пакетов не принадлежали юзеру root
$ sudo -u USERNAME php /var/www/USERNAME/packages.php /var/www/USERNAME/www/
Или от root, а после выставить владельца:
$ php /root/scripts/modx/packages.php /var/www/USERNAME/www/ && /var/www/USERNAME/chmod
Чтобы запустить из веба, просто положите скрипт в корень или куда-нибудь глубже и вызовите по HTTP
*/
@icyleaf
icyleaf / ar_migrate.rb
Last active October 13, 2023 03:21
ActiveRecord type of integer (tinyint, smallint, mediumint, int, bigint)
# activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
@mikekovacevic
mikekovacevic / faker_cheat_sheet.md
Last active October 2, 2023 05:38
Faker Ruby Gem Cheatsheet

A cheatsheet of all the Faker Wiki Pages

Faker::Address

  • city
  • city_prefix
  • city_suffix
  • country
  • postcode
  • secondary_address
  • state
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active March 7, 2024 03:56
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@racheldonovan
racheldonovan / wysihtml5_helper.rb
Created April 18, 2013 21:55
a helper to assit in integration testing (rspec / capybara) wysihtml5 text editors.
module Wysihtml5Helper
def fill_in_wysihtml5(text)
#js must be enabled
page.execute_script("editor.setValue('#{text}')")
end
end
@ryansobol
ryansobol / gist:5252653
Last active November 22, 2023 11:53
15 Questions to Ask During a Ruby Interview

Originally published in June 2008

When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.

To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.

What to expect

Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.

@wrburgess
wrburgess / README.md
Last active August 31, 2017 09:53
How to add a custom calculator for shipping or taxes to Spree
  1. Add initializer to config/application.rb
  2. Add new class to app/models/spree/calculators/[class_name].rb
  3. Add logic to class file

Class must have the following methods:

def self.description
  "Custom FlexiRate"
end