Skip to content

Instantly share code, notes, and snippets.

@miclast
miclast / request_logger.rb
Created November 16, 2021 16:02 — forked from jugyo/request_logger.rb
Rack middleware for logging all rails request
# Add below into config/application.rb:
#
# config.middleware.use 'RequestLogger'
#
class RequestLogger
def initialize app
@app = app
end
def call(env)
@miclast
miclast / dispatcher.list
Created September 6, 2021 07:41 — forked from krakatoa/dispatcher.list
Simple Kamailio round-robin configuration
# line format
# id(int,auto) setid(int) destination(string) flags(int) priority(int) attrs(string) description(string)
1 sip:10.0.0.9:5060
1 sip:10.0.0.10:5060
@miclast
miclast / sinatra+ssl.rb
Created September 2, 2021 19:22 — forked from TakahikoKawasaki/sinatra+ssl.rb
Sinatra + SSL
#!/usr/bin/env ruby
#
# This code snippet shows how to enable SSL in Sinatra.
#
require 'sinatra/base'
class Application < Sinatra::Base
configure do
set :bind, '0.0.0.0'
require "rubygems"
require "win32/service"
require "pp"
include Win32
options = {:service_name=>'ruby_example_service',
:service_type => Service::WIN32_OWN_PROCESS,
:description => 'A custom service I wrote just for fun',
:start_type => Service::AUTO_START,
@miclast
miclast / config.ru
Created July 6, 2021 04:49 — forked from benben/config.ru
basic ajax/sinatra example
$:.unshift File.expand_path(File.dirname(__FILE__))
require "viz"
run Sinatra::Application
@miclast
miclast / find_remove_old_activerecord.rb
Created June 10, 2021 16:34
Find/Remove ActiveRecord older than n days
# Get objects older than 3 days.
@models = MyModel.where('created_at < :time', { time: 3.days.ago })
@models = MyModel.where(['created_at < ?', 3.days.ago])
# Get objects within the last 3 days.
@models = MyModel.where('created_at >= :time', { time: 3.days.ago })
@models = MyModel.where(['created_at >= ?', 3.days.ago])
# Multiple conditions.
@models = MyModel.where(['created_at >= ? and name like ?', 3.days.ago, 'Sam%'])
@miclast
miclast / gist:f450a7eab90b60dd32f0d17e4363e692
Created June 9, 2021 06:44 — forked from unnitallman/gist:944011
sqlite with activerecord outside rails
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:dbfile => ":memory:"
)
@miclast
miclast / make-chr.sh
Created March 3, 2021 12:38 — forked from stroebs/make-chr.sh
Install Mikrotik CHR on a Digital Ocean droplet (Ubuntu 18.04 tested working 04/01/2021)
#!/bin/bash
#
# Digital Ocean Ubuntu 18.04 x64 Droplet
# Running:
# git clone https://gist.github.com/54fc09734a3911e91eeeb43434f117df.git
# cd 54fc09734a3911e91eeeb43434f117df/
# chmod +x make-chr.sh
# ./make-chr.sh
#
# Once the reboot is done, login with root/CHANGEME and change the password!
@miclast
miclast / unison.md
Created February 18, 2021 02:05 — forked from asksven/unison.md
Configure unison for continuous sync

Configure unison for bi-directional sync

1. On client

  1. Create a profile (~/.unison/bidirsync.prf):
# Unison preferences
label = bi-directonal sync with server
root = /home/<user>/git
root = ssh://<user>@<server-name>//home/<user>/sync/git
sshargs = -oIdentityFile=/home/<user>/.ssh/<privkey-name>
@miclast
miclast / Rakefile
Created January 31, 2021 15:05 — forked from schickling/Rakefile
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)