Skip to content

Instantly share code, notes, and snippets.

View gonglexin's full-sized avatar

Lexin Gong gonglexin

View GitHub Profile
@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
@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]
@staltz
staltz / introrx.md
Last active May 2, 2024 12:31
The introduction to Reactive Programming you've been missing
@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

@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)),
@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
@JEG2
JEG2 / struct.md
Created June 3, 2013 21:50
Thinking out loud about the merits and drawbacks of two different usages of Struct…

How Should We Use Struct?

The Choice

It's common in Ruby to see some code setup a Struct like this:

class Specialized < Struct.new(:whatever)
  # ... define custom methods here...
end