Skip to content

Instantly share code, notes, and snippets.

@miclast
miclast / .ruby-version
Created November 19, 2023 04:43 — forked from heygrady/.ruby-version
Example setup for running Unicorn on Ubuntu to manage Sinatra applications.
2.0.0@mygemset
@miclast
miclast / mikrotik-wireguard-default-gw.sh
Created May 12, 2023 18:05 — forked from olex0r/mikrotik-wireguard-default-gw.sh
Mikrotik wireguard client as default gateway
# You should change "XX.XX.XX.XX" to you wireguard server
# and set public-key,private-key,preshared-key,"YY.YY.YY.YY/YY" according to your config
/interface/wireguard/add name=wg0 private-key="[PRIVATE_KEY_HERE]"
/interface/wireguard/peers/add interface=wg0 endpoint-address=XX.XX.XX.XX endpoint-port=12321 public-key="[PUBLIC_KEY_HERE]" preshared-key="[PRESHARED_KEY_HERE]" persistent-keepalive=25s allowed-address=0.0.0.0/0
/ip/address/add interface=wg0 address=YY.YY.YY.YY/YY
/ip/route/add dst-address=XX.XX.XX.XX comment=wgserver disabled=yes
@miclast
miclast / multi.rb
Created February 5, 2023 18:01 — forked from hakanensari/multi.rb
Attach Net:HTTP requests to multiple local IPs
require 'net/http'
ips = `ifconfig | awk '/inet addr:[0-9]/{print $2;}' | grep -oE '([0-9.]{7,})'`.
split("\n").
select { |ip| ip.match(/\./) && !ip.match(/^127/) }
def attach_to(ip)
TCPSocket.instance_eval do
(class << self; self; end).instance_eval do
alias_method :original_open, :open
@miclast
miclast / proxy.rb
Created February 5, 2023 08:01 — forked from torsten/proxy.rb
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@miclast
miclast / ajax.rb
Created August 19, 2022 17:14 — forked from mayfer/ajax.rb
jQuery/AJAX/JSON/sinatra example
require 'sinatra'
require 'nokogiri'
require 'open-uri'
require 'sinatra/json'
# require 'json'
# sets the view directory correctly (to make it work with gists)
set :views, Proc.new { File.dirname(__FILE__) }
@miclast
miclast / Dockerfile
Created May 24, 2022 06:56 — forked from jmyoung/Dockerfile
Run Asterisk non-persistently in a Docker container
FROM centos:6
MAINTAINER James Young <[email protected]>
# Set up EPEL
RUN curl -L http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm -o /tmp/epel-release-6-8.noarch.rpm && \
rpm -ivh /tmp/epel-release-6-8.noarch.rpm && \
rm -f /tmp/epel-release-6-8.noarch.rpm
# Update and install asterisk
RUN yum update -y && yum install -y asterisk
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@miclast
miclast / Rakefile
Created February 16, 2022 02:02 — forked from vast/Rakefile
Interactive console for sinatra + activerecord
require 'my-sinatra-app'
require 'sinatra/activerecord/rake'
desc "run irb console"
task :console, :environment do |t, args|
ENV['RACK_ENV'] = args[:environment] || 'development'
exec "irb -r irb/completion -r my-sinatra-app"
end
@miclast
miclast / encrypt_decrypt.rb
Created December 6, 2021 06:25 — forked from wteuber/encrypt_decrypt.rb
Simply encrypt and decrypt Strings in Ruby.
require 'openssl'
class String
def encrypt(key)
cipher = OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
cipher.key = Digest::SHA1.hexdigest key
s = cipher.update(self) + cipher.final
s.unpack('H*')[0].upcase
end