Skip to content

Instantly share code, notes, and snippets.

View Nondv's full-sized avatar

Dmitry Non Nondv

View GitHub Profile
@Nondv
Nondv / lambda_instead_of_methods.rb
Last active April 18, 2017 21:21
[Ruby] Using lambda instead of methods
module CreatedAtScopes
extend ActiveSupport::Concern
# Lambda does not pollute a class namespace but do the job.
tz_time_today = -> { Time.zone.now.beginning_of_day }
included do
scope :created_before, ->(time) { where(arel_table[:created_at].lt(time)) }
scope :created_after, ->(time) { where(arel_table[:created_at].gt(time)) }
scope :created_today, -> { created_after(tz_time_today[]) }
scope :created_yesterday, -> { created_after(tz_time_today[] - 1.day).created_before(tz_time_today[]) }
@ghoseb
ghoseb / ns-cheatsheet.clj
Last active March 25, 2025 21:21 — forked from alandipert/ns-cheatsheet.clj
Clojure ns syntax cheat-sheet
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix
;; and optionally can refer functions to the current ns.
;;
;; * :import refers Java classes to the current namespace.
;;
;; * :refer-clojure affects availability of built-in (clojure.core)
;; functions.