Skip to content

Instantly share code, notes, and snippets.

View gonglexin's full-sized avatar

Lexin Gong gonglexin

View GitHub Profile
@pedro
pedro / Gemfile
Last active December 18, 2015 03:18
Testing ActiveRecord performance
source "https://rubygems.org"
gem "pg"
gem "sqlite3"
unless version = ENV["AR"]
abort("specify ActiveRecord version with AR. eg: AR=2 bundle install")
else
gem "activerecord", "~> #{version}", require: "active_record"
end
@be9
be9 / paginate.rb
Created September 5, 2013 04:18
kaminari + JSON API pagination helper
def paginate(scope, default_per_page = 20)
collection = scope.page(params[:page]).per((params[:per_page] || default_per_page).to_i)
current, total, per_page = collection.current_page, collection.num_pages, collection.limit_value
return [{
pagination: {
current: current,
previous: (current > 1 ? (current - 1) : nil),
next: (current == total ? nil : (current + 1)),
@runlevel5
runlevel5 / lotus_console.md
Last active August 29, 2015 14:02
A simple rake task that replicates the `rails console` for Lotus Framework

Lotus Console

A simple rake task that replicates the rails console for Lotus Framework

How to?

I assume that your config/application.rb is the place where you initialize all Lotus boot config

below is my config/application.rb for your interest

@staltz
staltz / introrx.md
Last active May 4, 2025 15:01
The introduction to Reactive Programming you've been missing
@pramodshinde
pramodshinde / gmail.rb
Last active March 31, 2021 07:19
Gmail API (via IMAP) using gmail_xoauth - Example
# An example demonstrating Gmail API via IMAP using gmail_xoauth gem
# Add this file to your rails project to use if you don't want to use this in rails project then require
require 'net/imap'
require 'gmail_xoauth'
class Gmail
attr_accessor :email, :access_token
def initialize(args)
email = args[:email]
@eddiefisher
eddiefisher / _form.html.slim
Created March 22, 2015 15:16
refile multiply file upload
= semantic_nested_form_for @gallery, multipart: true do |form|
= form.input :file_multiple, as: :file, input_html: { multiple: true }
= form.actions do
= form.action :submit
@alanpeabody
alanpeabody / my_app.ex
Last active February 19, 2025 16:29
Websockets in Elixir with Cowboy and Plug
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
Plug.Adapters.Cowboy.child_spec(:http, MyApp.Router, [], [
dispatch: dispatch
])
@drbrain
drbrain / nightmares.rb
Last active July 25, 2017 17:40
A method that has a default argument that defines a method that contains a here-document
def a l = def b; <<-NIGHTMARES; end; puts send l; end
😱😱😱
NIGHTMARES
a