Skip to content

Instantly share code, notes, and snippets.

@lazybios
lazybios / install-ruby.sh
Created May 29, 2022 10:56 — forked from hopsoft/install-ruby.sh
Install ruby with rbenv and jemalloc on ubuntu
sudo apt-get update
sudo apt-get install libjemalloc-dev
RUBY_CONFIGURE_OPTS='--with-jemalloc' rbenv install 2.6.3
# test (look for jemalloc warnings)
MALLOC_CONF=invalid_flag:foo ruby -v
@lazybios
lazybios / custom_logger.rb
Created May 6, 2022 10:31 — forked from kinopyo/custom_logger.rb
Custom logger file in Rails
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere
@lazybios
lazybios / gist:9b3c5dc54f38dca2de73af1a4e0b4b54
Created October 11, 2021 12:36 — forked from bsodmike/gist:1369419
Subdomain Routing with Rails 3.1

Implement Routing for Subdomains

Rails 3.0 introduced support for routing constrained by subdomains.

A subdomain can be specified explicitly, like this:

match '/' => 'home#index', :constraints => { :subdomain => 'www' } 
@lazybios
lazybios / redis_factory.lua
Created May 22, 2018 11:52 — forked from karminski/redis_factory.lua
lua redis factory for lua-resty-redis, can work with nginx + nginx-lua-module or openresty.
--[[
redis_factory.lua
Redis factory method.
You can also find it at https://gist.github.com/karminski/33fa9149d2f95ff5d802
@version 151019:5
@author karminski <[email protected]>
@license MIT
@lazybios
lazybios / gist:e130d3d67f55e554c3a222418ecde1d0
Created November 30, 2017 13:33 — forked from fitzyyf/gist:5276821
Python 通过SSH执行远程命令
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# See http://www.cnblogs.com/ma6174/archive/2012/05/25/2508378.html
import pexpect
import paramiko
import threading
import yaml
@lazybios
lazybios / polymorphic_ass_grape_entity
Created February 14, 2017 06:49 — forked from ordoghl/polymorphic_ass_grape_entity
Polymorphic association in a grape entity
require_relative 'customer.rb'
require_relative 'contact.rb'
require_relative 'agent.rb'
module Api
module V1
module Entities
class Ticket < Grape::Entity
expose :id
@lazybios
lazybios / wr703n-openwrt.md
Created June 26, 2016 07:55 — forked from simpx/wr703n-openwrt.md
wr703n刷openwrt配置、记录
@lazybios
lazybios / registrations_controller.rb
Created January 7, 2016 02:40 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@lazybios
lazybios / things.rb
Created December 29, 2015 04:52
a script to analyze your Things app
#!/usr/bin/env ruby
# Usuage
# things 'thisweek'
# things 'lastweek'
# things 'thismonth'
require 'fileutils'
require 'date'
# please install the following 5 gems.
@lazybios
lazybios / .railsrc
Created December 21, 2015 10:48 — forked from ivanoats/.railsrc
# .railsrc
-B #Skip Bundle
-T #Skip Test-Unit
-d postgresql #Use postgres