Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔
trying to quit vim

Anton Maminov mamantoha

🤔
trying to quit vim
View GitHub Profile
@mamantoha
mamantoha / is_port_open.cr
Created Aug 21, 2019
A quick way to find out if a given port is open with Crystal.
View is_port_open.cr
require "socket"
def is_port_open?(ip : String, port : Int32, timeout = 5)
s = TCPSocket.new(ip, port, dns_timeout: timeout, connect_timeout: timeout)
s.close
true
rescue IO::Timeout
false
end
View pry_everywhere.rb
# config/initializers/pry_everywhere.rb
require 'sidekiq'
# Perform Sidekiq jobs immediately in development,
# so you don't have to run a separate process.
# You'll also benefit from code reloading.
if Rails.env.development? && ENV['SIDEKIQ_INLINE'].present?
require 'sidekiq/testing'
Sidekiq::Testing.inline!
end
@mamantoha
mamantoha / polymorphic_many_to_many_in_rails.md
Created Apr 5, 2018
polymorphic_many_to_many_in_rails.md
View polymorphic_many_to_many_in_rails.md

Polymorphic many-to-many association in Rails

Migration

class CreateBannerCategories < ActiveRecord::Migration
  def change
    create_table :banner_categories do |t|
      t.integer :banner_id
      t.integer :category_id
View ilsap.cr
# ilsap - Intellij License Server Active Proxy
#
# Since Jetbrains started to blacklist license servers by hostname, it's being a pain in the ass
# to find a working one. So this is an active proxy for Intellij license servers, that masks
# a license server into your localhost. Just create a startup script to call ilsap,
# configure your IDE to activate from the localhost and YOLO!
#
require "http/server"
require "http/client"
@mamantoha
mamantoha / _.md
Last active Jun 15, 2017
Ruby goto
View _.md
@mamantoha
mamantoha / uk.rb
Created Apr 18, 2017
Ukrainian language support for Ruby on Rails
View uk.rb
# config/locales/defaults/uk.rb
{
uk: {
date: {
# In Ukrainian month name with day and standalone day are different
month_names: lambda do |key, options|
if options[:format] && options[:format] =~ /%-?d %B/
:'date.month_names_with_day'
else
:'date.month_names_standalone'
@mamantoha
mamantoha / query.rb
Created Nov 17, 2016
PostgreSQL: query to select records from last week on weekdays between 9:00 and 18:00
View query.rb
Model
.where(
"EXTRACT(dow FROM log_in) IN (1,2,3,4,5)"
)
.where(
"log_in::time BETWEEN '9:00' AND '18:00'"
)
.where(
"log_in BETWEEN now()::timestamp - (interval '1 week' AND now()::timestamp)"
)
@mamantoha
mamantoha / is_github_down.rb
Last active Oct 6, 2016
Small CLI tool to tell you if GitHub is online
View is_github_down.rb
require 'net/http'
def warning_message
puts <<~HEREDOC
Usage:
$ is_github_down
🦄 It's down. Go outside!
HEREDOC
@mamantoha
mamantoha / set_kde_wallpaper.rb
Last active Apr 16, 2018
Ruby script to change desktop wallpaper in Plasma > 5.7 from GoPro photo of the day
View set_kde_wallpaper.rb
require 'net/http'
require 'open-uri'
require 'open3'
require 'json'
require 'optparse'
require 'tempfile'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} [options]"
@mamantoha
mamantoha / set_wallpaper
Created Jul 22, 2016
Set desktop wallpaper in Plasma5 via a dbus command
View set_wallpaper
qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript 'var allDesktops = desktops();print (allDesktops);for (i=0;i<allDesktops.length;i++) {d = allDesktops[i];d.wallpaperPlugin = "org.kde.image";d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");d.writeConfig("Image", "file:///path/to/image.png")}'