Skip to content

Instantly share code, notes, and snippets.

@krists
krists / my_tracer.rb
Created October 10, 2023 14:05
MyTracer
class MyTracer < BasicObject
def initialize(obj)
@original_obj = obj
end
def method_missing(method, *args, **kw_args, &block)
if @original_obj.respond_to?(method)
::Kernel.puts "Method Missing: #{method} | #{args.inspect} | #{kw_args.inspect}"
@original_obj.send(method, *args, **kw_args, &block)
else
require 'bundler/inline'
require "thread"
require "tempfile"
gemfile do
source 'https://rubygems.org'
gem 'sqlite3', '1.3.13'
gem 'pry'
end
@krists
krists / clear-screen.sh
Created January 5, 2018 16:31
Clear screen in Linux terminal
#!/bin/bash
clear && printf '\e[3J'
@krists
krists / assets.rake
Created March 13, 2016 18:30
Compile Rails assets locally and rsync them to server (Capistrano 3)
# lib/capistrano/tasks/assets.rake
namespace :assets do
desc "Precompile assets locally and then rsync to web servers"
task :precompile do
on roles(:web) do
rsync_host = host.to_s
run_locally do
with rails_env: fetch(:stage) do
execute :bundle, "exec rake assets:precompile"
end
@krists
krists / arrow.rb
Created December 3, 2015 13:19
Method that calculates all vectors to draw an arrow
require "matrix"
require "cmath"
module Arrow
# Example arrow(6, 4, Vector[10, 10], Vector[100, 100])
def arrow(arrowhead_length, half_width, foot_vector, tip_vector)
h = arrowhead_length.to_f * CMath.sqrt(3)
w = half_width.to_f
u = (tip_vector - foot_vector) / (tip_vector - foot_vector).norm
@krists
krists / extip
Last active August 29, 2015 14:22
What is my external IP address
#!/usr/bin/env ruby
require "net/http"
require "json"
uri = URI('https://duckduckgo.com/?q=what+is+my+ip&format=json&no_html=1')
response = Net::HTTP.get_response(uri)
if response.is_a?(Net::HTTPSuccess)
parsed_response = JSON.parse(response.body)
answer = parsed_response["Answer"]
@krists
krists / row-power-vagrant-box-install-notes.md
Last active August 29, 2015 14:18
RoR Power Vagrant box for Ruby projects

Install notes

  1. Download Vagrant box from https://onedrive.live.com/redir?resid=9c863f656a51c19b%2159142
  2. Add downloaded file to usable boxes with command:
  • vagrant box add centos-6.6-ror-power.v1.0 centos-6.6-ror-power.v1.0.box
  1. Initialize Vagrant into your project
  • vagrant init centos-6.6-ror-power.v1.0
  1. Replace VagrantFile with recommended configuration optimized for speed:
Vagrant.configure(2) do |config|
 config.vm.box = "centos-6.6-ror-power.v1.0"
@krists
krists / Turn CAPSLOCK to Ctrl.reg
Last active February 3, 2024 21:23
Remap Caps-Lock key to Ctrl in Windows 7/8
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
@krists
krists / gist:5860211
Created June 25, 2013 16:57
Install latest stable nginx on ubuntu
sudo apt-get install python-software-properties software-properties-common
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
service nginx status
@krists
krists / install_hstore.sh
Last active December 18, 2015 22:49
Enable hstore for default PostgreSQL database template with one command.
sudo su - postgres -c "psql -d template1 -c 'create extension if not exists hstore;'"