Skip to content

Instantly share code, notes, and snippets.

View adis-io's full-sized avatar

Adis Osmonov adis-io

View GitHub Profile
#! /bin/bash
items="1 2 3 4 5 6"
pids=""
for item in $items; do
sleep $item &
pids+="$! "
done
[
{
"keys": ["command+enter"],
"command": "delete_trailing_spaces"
},
{
"keys": ["command+shift+/"],
"command": "reveal_in_side_bar"
},
{
@adis-io
adis-io / re_raise_exception_in_ruby.rb
Last active October 10, 2016 14:16
Re raise exception with custom message
env = ENV.fetch('APP_ENV', 'development')
begin
storage_config = YAML.load_file("#{Rails.root.to_s}/config/storage.yml")[env]
rescue Errno::ENOENT
message = ".config/storage.yml not found! Perhaps you forgot to copy it from storage.yml.example? (#{$!})"
raise $!, message, $!.backtrace
end
@adis-io
adis-io / delete_old_wp_posts.sql
Last active September 24, 2016 05:59
Delete all old posts which published 600 days ago
DELETE a, b, c
FROM
wp_posts a
LEFT JOIN
wp_term_relationships b ON(a.ID = b.object_id)
LEFT JOIN
wp_postmeta c ON(a.ID = c.post_id)
WHERE
a.post_type = 'post' AND DATEDIFF(NOW(),
a.post_date) > 600
Authentication: I am who I say I am
Authorization: What am I allowed to do?
class RegistrationsController < Devise::RegistrationsController
def create
super do |resource|
if resource.persisted?
resource.send_confirmation_instructions
end
end
end
end
@adis-io
adis-io / default.conf
Created May 5, 2016 09:47
nginx default server
server {
listen 80 default_server;
server_name _;
return 444;
}
@adis-io
adis-io / mailer_example.rb
Created April 19, 2016 15:04
Ruby script to send email though ActionMailer
require 'action_mailer'
ActionMailer::Base.smtp_settings = {
address: 'smtp.yourserver.com', # default: localhost
port: '25', # default: 25
user_name: 'user',
password: 'pass',
authentication: :plain # :plain, :login or :cram_md5
}
@adis-io
adis-io / active_admin.js
Created December 24, 2015 11:16
Chained select in ActiveAdmin
if ($('body').hasClass('admin_subscriptions')) {
$.post('/admin/users/1/subscriptions/get_subjects', function(data) {
$('body').data('subscription.subjects', data);
});
$("#subscription_subject_type").on("change", function () {
var $select_type = $("#subscription_subject_type"),
$select_id = $("#subscription_subject_id");
$("option[value]", $select_id).remove();
$.each($('body').data('subscription.subjects'), function() {