Skip to content

Instantly share code, notes, and snippets.

View zires's full-sized avatar
🎎
anxiety

zshuaibin zires

🎎
anxiety
View GitHub Profile
@zires
zires / gist:dcfe89853658096cc5bbd5d37cc645df
Created January 11, 2021 02:43 — forked from bonyiii/gist:1985562
How to make an activerecord model use a tempory table or view dynamically per query
# Creating view or temp table
ActiveRecord::Base.connection.execute("CREATE TEMPORARY TABLE users#{args.offset} SELECT * FROM users LIMIT #{limit} OFFSET #{(args.offset - 1) * limit}")
# or
ActiveRecord::Base.connection.execute("CREATE VIEW users#{args.offset} AS SELECT * FROM users LIMIT #{limit} OFFSET #{(args.offset - 1) * limit}")
### Giving relation back, suitable for find_in_batches
#User.arel_table.name ='users2'
# This changes table name in FROM part of the query
@zires
zires / unicorn_tour.md
Created June 5, 2020 06:00 — forked from jhjguxin/unicorn_tour.md
like unix better,deploy rails application with unicorn + nginx <br/> the tour base on guanxi_cms

Unicorn: Rack HTTP server for fast clients and Unix

Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels. Slow clients should only be served by placing a reverse proxy capable of fully buffering both the the request and response in between Unicorn and slow clients.

Features

  • Designed for Rack, Unix, fast clients, and ease-of-debugging. We cut out everything that is better supported by the operating system, nginx or Rack.
  • Compatible with both Ruby 1.8 and 1.9. Rubinius support is in-progress.
  • Process management: Unicorn will reap and restart workers that die from broken apps. There is no need to manage multiple processes or ports yourself. Unicorn can spawn and manage any number of worker processes you choose to scale to your backend.
  • Load balancing is done entirely by the operating system kernel. Requests never pile up behind a bus
@zires
zires / gist:b9676abf0e40a9ca398b9abc1926f4b0
Created May 2, 2018 02:24 — forked from tomstuart/gist:1466504
FizzBuzz in the lambda calculus in Ruby
>> IF = -> b { b }
=> #<Proc:0x007fb4e4049cc8 (lambda)>
>> LEFT = -> p { p[-> x { -> y { x } } ] }
=> #<Proc:0x007fb4e403d680 (lambda)>
>> RIGHT = -> p { p[-> x { -> y { y } } ] }
=> #<Proc:0x007fb4e4028ff0 (lambda)>
>> IS_EMPTY = LEFT
@zires
zires / redis_helper.rb
Created April 14, 2016 03:14 — forked from wxmn/redis_helper.rb
How to Build a Fast News Feed in Redis and Rails
module RedisHelper
# decode Redis value back to Ruby object
def self.decode(json)
self.new(ActiveSupport::JSON.decode(json)["#{self.name.downcase}"])
end
# encode Ruby object for Redis
def encoded
self.updated_at = nil
self.to_json
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@zires
zires / mongodb
Last active August 29, 2015 14:10 — forked from pasviegas/mongodb
check host mongodb with address localhost
start program = "/usr/bin/sudo /opt/database/mongo/bin/mongod"
stop program = "/usr/bin/sudo /usr/bin/pkill -f mongod"
if failed port 28017 protocol HTTP
request /
with timeout 10 seconds
then start
@zires
zires / monitrc
Last active August 29, 2015 14:10 — forked from franck/monitrc
###############################################################################
## Monit control file
###############################################################################
##
## Comments begin with a '#' and extend through the end of the line. Keywords
## are case insensitive. All path's MUST BE FULLY QUALIFIED, starting with '/'.
##
## Below you will find examples of some frequently used statements. For
## information about the control file, a complete list of statements and
## options please have a look in the monit manual.