Skip to content

Instantly share code, notes, and snippets.

View kossoff's full-sized avatar

Anthony kossoff

View GitHub Profile
def luhn(code)
(code
.chars # Break into individual digits
.map(&:to_i) # map each character by calling #to_i on it
.reverse # Start from the end
.map.with_index { |x, i| i.odd? ? x * 2 : x } # Double every other digit
.map { |x| x > 9 ? x - 9 : x } # If > 9, subtract 9 (same as adding the digits)
.inject(0, :+) % 10).zero? # Check if multiple of 10
end
@kossoff
kossoff / puma.rb
Created August 17, 2019 10:04
Puma config template
#!/usr/bin/env puma
# The directory to operate out of.
#
# The default is the current directory.
#
# directory '/u/apps/lolcat'
# Use an object or block as the rack application. This allows the
# config file to be the application itself.
@kossoff
kossoff / watcher.rb
Created November 8, 2016 09:55
Service for watch Dropbox folder on linux & send notifications to Slack if new files added
#!/home/RUBYUSER/.rvm/rubies/ruby-2.3.0/bin/ruby
require 'rubygems'
require 'rb-inotify'
require 'slack-notifier'
watcher = INotify::Notifier.new
notifier = Slack::Notifier.new "https://hooks.slack.com/services/SLACKWEBHOOKURL"
notifier.channel = '#CHANNEL_NAME'
@kossoff
kossoff / test.html.slim
Created September 8, 2016 08:19
Custom parameters for jQuery Datatables with server-side processing
label
input#test-checkbox type="checkbox"
|Test checkbox
table#test-table
javascript:
$(document).ready(function() {
var table = $("#test-table").dataTable( {
"ajaxSource": '#{test_datatable_path}',
@kossoff
kossoff / change_modules_location_in_drupal.txt
Created July 3, 2016 07:10
How to move installed modules from /sites/all/modules/* to /sites/all/contrib/modules/*
I restored a backup from production locally and tried to just move things and hit admin/modules or to run registry_rebuild() but it didn't stop fatal errors from being thrown. This makes sense to me since some modules may use includes or whatever in their hook_init(), or you may have a menu router path set that depends on a module or include that Drupal can't find on bootstrap. Ultimately, this is what I did (your paths may be different):
Step 1: Replace sites/all/modules with sites/all/modules/contrib
UPDATE system SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
UPDATE registry SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
UPDATE registry_file SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
Step 2: Replace sites/all/modules/contrib with sites/all/modules/custom for custom namespaced modules
UPDATE system SET filename = REPLACE(filename, 'sites/all/modules/contrib', 'sites/all/modules/custom') WHER
require 'rubygems'
require "net/http"
require "net/https"
require 'nokogiri'
XML = Nokogiri::HTML open "sitemap.xml"
links = XML.css "loc"
links.each do |link|
uri = URI link.text
Exorcizo te, immundissime spiritus, omnis incursio adversarii, omne phantasma, omnis legio, in nomine Domini nostri Jesu Christi eradicare, et effugare ab hoc plasmate Dei. Ipse tibi imperat, qui te de supernis caelorum in inferiora terrae demergi praecepit. Ipse tibi imperat, qui mari, ventis, et tempestatibus impersvit. Audi ergo, et time, satana, inimice fidei, hostis generis humani, mortis adductor, vitae raptor, justitiae declinator, malorum radix, fomes vitiorum, seductor hominum, proditor gentium, incitator invidiae, origo avaritiae, causa discordiae, excitator dolorum: quid stas, et resistis, cum scias. Christum Dominum vias tuas perdere? Illum metue, qui in Isaac immolatus est, in joseph venumdatus, in sgno occisus, in homine cruci- fixus, deinde inferni triumphator fuit. Sequentes cruces fiant in fronte obsessi. Recede ergo in nomine Patris et Filii, et Spiritus Sancti: da locum Spiritui Sancto, per hoc signum sanctae Cruci Jesu Christi Domini nostri: Qui cum Patre et eodem Spiritu Sancto vivit et r
@kossoff
kossoff / update_price_by_csv.php
Created September 22, 2015 18:34
Drupal 7. Обновление/добавление цен для товаров из CSV-файла. Ключ - уникальный title.
<?php
header('Content-Type: text/html; charset=UTF-8');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
require_once DRUPAL_ROOT . '/includes/common.inc';
require_once DRUPAL_ROOT . '/includes/module.inc';
require_once DRUPAL_ROOT . '/includes/unicode.inc';
require_once DRUPAL_ROOT . '/includes/file.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
@kossoff
kossoff / update_price_by_currency_rate.php
Created September 22, 2015 18:26
Для Drupal 7. Меняем значение поля price_ru в соответсвии с курсом евро с сайта ЦБ РФ. Исходная цена = price_eu
<?php
header('Content-Type: text/html; charset=UTF-8');
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
require_once DRUPAL_ROOT . '/includes/common.inc';
require_once DRUPAL_ROOT . '/includes/module.inc';
require_once DRUPAL_ROOT . '/includes/unicode.inc';
require_once DRUPAL_ROOT . '/includes/file.inc';
@kossoff
kossoff / index
Last active August 29, 2015 14:16
Disable right click & context menu for page
<body oncontextmenu="return false">
...
<script>
document.onmousedown=disableclick;
function disableclick ( event ) {
if ( event.button == 2 ) { return false; }
};
</script>