Skip to content

Instantly share code, notes, and snippets.

View raykin's full-sized avatar

raykin raykin

  • Shanghai,China
View GitHub Profile
@barbolo
barbolo / benchamark_hash_to_json.rb
Last active September 24, 2022 03:32
Benchmark of JSON rendering in Ruby
# gem install multi_json json yajl-ruby oj benchmark-memory
require 'multi_json'
require 'json'
require 'yajl'
require 'oj'
require 'benchmark'
require 'benchmark-memory'
hash1 = {
comment = "# frozen_string_literal: true\n"
filemode = "r+"
dirs = Dir[Rails.root.join('spec/**/*.rb').to_s] + Dir[Rails.root.join('lib/**/*.rake').to_s] + Dir[Rails.root.join('lib/**/*.rb').to_s]
dirs.each do |filename|
contents = File.open(filename, "r") do |f|
f.read
end
contents = comment + contents
@gkastrinis
gkastrinis / post3.md
Last active June 3, 2020 13:50
SSH Tunneling (a.k.a. Port Forwarding)

SSH Tunneling (a.k.a. Port Forwarding)

In general, SSH tunneling creates a secure connection between a local computer and a remote machine through which services can be relayed (the important part). Because the connection is encrypted, SSH tunneling is useful for transmitting information that uses an unencrypted protocol, such as IMAP, VNC, or IRC (the not-so-important part).

A case where I found this to be a useful technique was when I had a remote machine running a web server but because of various reasons (e.g. security concerns) there was no public open port available (that I could use). If such a port existed (e.g. 9876), I could simply access the web server from my favorite web browser just by providing the appropriate URL address (e.g. http://example.com:9876). But fortunately enough, I had SSH access to that remote machine.

This is how it works:

@nicolasembleton
nicolasembleton / restart_bluetooth.sh
Last active May 11, 2024 17:43
Restart Bluetooth Daemon on Mac OS X without restarting
#!/bin/bash
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
@rkjha
rkjha / nginx-config-rails4-with-puma-ssl-version.conf
Last active November 2, 2023 11:57
Nginx config for rails 4 application using puma [ssl and non-ssl version]
upstream myapp_puma {
server unix:/tmp/myapp_puma.sock fail_timeout=0;
}
# for redirecting to https version of the site
server {
listen 80;
rewrite ^(.*) https://$host$1 permanent;
}
@mattetti
mattetti / tracepoint_middlware.rb
Created March 6, 2013 06:34
test middleware for Ruby 2.0 logging the method dispatches going on when a request is being handled.
class TracePoint
class Middleware
def initialize(app)
@app = app
end
def call(env)
stats = {}
trace = TracePoint.new(:call) do |tp|
@nhance
nhance / method_logger.rb
Created September 6, 2012 12:58
Rails compatible method logging. Use this to log all calls to instance methods of a class to the log.
Model.new.foo
@andreyvit
andreyvit / tmux.md
Created June 13, 2012 03:41
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@mbleigh
mbleigh / Gemfile
Created March 21, 2012 03:14
Non-Rails Rackup with Sprockets, Compass, Handlebars, Coffeescript, and Twitter Bootstrap
source "https://rubygems.org"
gem 'sprockets'
gem 'sprockets-sass'
gem 'sass'
gem 'compass'
gem 'bootstrap-sass'
gem 'handlebars_assets'
gem 'coffee-script'