Skip to content

Instantly share code, notes, and snippets.

View gingerhot's full-sized avatar
🎯
Focusing

B1nj0y gingerhot

🎯
Focusing
View GitHub Profile
@gingerhot
gingerhot / fusion.thor
Created July 5, 2018 01:12 — forked from onemanstartup/fusion.thor
templating in thor
# Default Middleman template
class Fusion < Thor::Group
include Thor::Actions
argument :location, :type => :string
class_option "css_dir",
:default => "css",
:desc => 'The path to the css files'
class_option "js_dir",
@gingerhot
gingerhot / download_pages.rb
Created June 22, 2018 07:00 — forked from justinxreese/download_pages.rb
Limit open threads in ruby
# Pretty simple solution to harness the capability of multithreading without running into problems
# caused by doing too many things at once.
# In this example, I was trying to download hundreds of web pages, but opening all those connections
# simultaneously caused a variety of errors
# Contains download_link(link,save_dir,save_name) to download and save webpages locally (irrelevant)
require 'download_page'
# keep the threads in here
@gingerhot
gingerhot / NERDTree Commands
Created June 7, 2018 08:33 — forked from adamdb/NERDTree Commands
A list of useful NERDTree commands.
Use the natural Vim navigation keys hjkl to navigate the files.
Press o to open the file in a new buffer or open/close directory.
Press t to open the file in a new tab.
Press i to open the file in a new horizontal split.
Press s to open the file in a new vertical split.
Press p to go to parent directory.
Press r to refresh the current directory.
Press m to launch NERDTree menu inside Vim.
@gingerhot
gingerhot / application_helper.rb
Created March 19, 2018 07:20 — forked from mynameispj/application_helper.rb
Rails - Easy "active" classes for menu links in Rails
module ApplicationHelper
def current_class?(test_path)
return 'active' if request.path == test_path
''
end
end
var token = $('meta[name="csrf-token"]').attr('content');
$.ajax({
url : myurl,
headers: {
'X-Auth-Token' : token
});
@gingerhot
gingerhot / deploy.rb
Created February 27, 2018 03:48 — forked from gilcierweb/deploy.rb
Mina deploy ruby on rails 5.1 ++
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv' # for rbenv support. (https://rbenv.org)
# require 'mina/rvm' # for rvm support. (https://rvm.io)
set :application_name, 'my_app'
set :domain, 'my_server'
set :deploy_to, '/home/rails/my_app'
set :repository, '[email protected]:my_user/my_app.git'
set :branch, 'master'
@gingerhot
gingerhot / signal_catching.rb
Created February 1, 2018 06:07 — forked from sauloperez/signal_catching.rb
How to catch SIGINT and SIGTERM signals in Ruby
# Signal catching
def shut_down
puts "\nShutting down gracefully..."
sleep 1
end
puts "I have PID #{Process.pid}"
# Trap ^C
Signal.trap("INT") {
@gingerhot
gingerhot / README.md
Created January 30, 2018 05:17 — forked from fnichol/README.md
A Common .ruby-version File For Ruby Projects

A Common .ruby-version File For Ruby Projects

Background

I've been using this technique in most of my Ruby projects lately where Ruby versions are required:

  • Create .rbenv-version containing the target Ruby using a definition name defined in ruby-build (example below). These strings are a proper subset of RVM Ruby string names so far...
  • Create .rvmrc (with rvm --create --rvmrc "1.9.3@myapp") and edit the environment_id= line to fetch the Ruby version from .rbenv-version (example below).

Today I learned about another Ruby manager, rbfu, where the author is using a similar technique with .rbfu-version.

@gingerhot
gingerhot / Mina.md
Created January 15, 2018 06:49 — forked from stevenyap/Mina.md
Mina - Faster deployment than Capistrano!!!
@gingerhot
gingerhot / graceful.go
Created January 7, 2018 06:07 — forked from peterhellberg/graceful.go
*http.Server in Go 1.8 supports graceful shutdown. This is a small example.
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
)