Skip to content

Instantly share code, notes, and snippets.

View dmitryck's full-sized avatar

dmitryck dmitryck

  • krasava
View GitHub Profile
@shuber
shuber / add_index_patch.rb
Created April 1, 2015 07:43
ActiveRecord `add_index` patch for PostgreSQL JSONB GIN indexes
# This patch detects {index_columns} that match something like
# the example below, then strips the surrounding double quotes.
#
# "(settings->'example')"
#
# The resulting CREATE INDEX sql looks something like:
#
# CREATE INDEX "idx_users_on_settings_example" ON "users" USING gin ((settings->>'example'))
#
# Your {add_index} call should looks something like:
#!/usr/bin/env ruby
# Usage
# $ htpasswd.rb 'your_usrename', 'your_password'
# UseCase
# Generate htpasswd for nginx without apache tools.
require "base64"
username, password = ARGV
salt = Base64.encode64((("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a).shuffle[0..7].join)
puts "#{username}:#{password.crypt(salt)}"
@Ravenstine
Ravenstine / reactor.cr
Created September 8, 2015 05:29
A very simple event loop written in Crystal. (crystal-lang.org)
module Reactor
class Task
property :block
def initialize(timestamp=Time.now, milliseconds=0, &block : Loop ->)
@block = block
@timestamp = timestamp.epoch_ms
@milliseconds = milliseconds
end
def run reactor
@EmmanuelOga
EmmanuelOga / callback.rb
Created December 1, 2011 15:54
callback test.
require 'benchmark'
class Proc
def slow_callback(callable, *args)
self === Class.new do
method_name = callable.to_sym
define_method(method_name) { |&block| block.nil? ? true : block.call(*args) }
define_method("#{method_name}?") { true }
def method_missing(method_name, *args, &block) false; end
end.new
@cmouse
cmouse / gist:27c2af929d0e3c31d24b
Created January 13, 2015 13:48
bgp-peer test
require 'rubygems'
require 'bgp4r'
require 'yaml'
require 'observer'
require 'daemons'
include BGP
# Set this where your config file is
configFile = "/etc/bgp-daemon.conf"
@Val
Val / build_rest-like_api.rb
Created January 19, 2016 14:28
Token protected REST-like API using Grape, Swagger on top of Rails. Based on http://www.toptal.com/ruby/grape-gem-tutorial-how-to-build-a-rest-like-api-in-ruby/
# -*- mode:ruby;tab-width:2;indent-tabs-mode:nil;coding:utf-8 -*-
# vim: ft=ruby syn=ruby fileencoding=utf-8 sw=2 ts=2 ai eol et si
#
# build_rest-like_api.rb: sample REST-like API server
# (c) 2016 Laurent Vallar <val@zbla.net>, WTFPL license v2 see below.
#
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
@itsamoreh
itsamoreh / caps-as-escape
Last active October 29, 2019 15:20
Dconf remap caps as escape - Tested on Ubuntu 16.10
dconf write /org/gnome/desktop/input-sources/xkb-options "['caps:escape']"
@MattWoelk
MattWoelk / workman.vim
Created March 25, 2011 23:45
workman keyboard layout for vim
"A blatant workman ripoff of bmx 007's beautiful colemak version called 'colqer' http://www.vim.org/scripts/script.php?script_id=2865 It makes vim so that you can insert and Ex mode in the workman keyboard layout, but can do the rest in qwerty.
"usage: put it in ~/.vim/plugin/ as workman.vim
"press \; in normal mode to activate/deactivate it.
"Keyboard is qwerty
" we want workman in insert mode
function IMapColemak()
if s:imap_colemak == 0
noremap! q q
noremap! w d
@dalibor
dalibor / Rails model without table
Created November 7, 2009 11:03
Rails model without table
#In app/models/tableless.rb
class Tableless < ActiveRecord::Base
def self.columns
@columns ||= [];
end
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default,
sql_type.to_s, null)
end
@theinventor
theinventor / teamviewer.rb
Created April 1, 2014 17:30
A quick ruby api wrapper for the teamviewer api
module Teamviewer
class Connector
attr_reader :client
def initialize
@client = connection(credentials)
end