Skip to content

Instantly share code, notes, and snippets.

View Nondv's full-sized avatar

Dmitry Non Nondv

View GitHub Profile
@Nondv
Nondv / navigation-mode.el
Last active December 9, 2024 12:56
My custom navigation minor mode for emacs (to move around the code file without holding control down)
;; I often find myself simply jumping around the code to read it.
;; However, it's a bit daunting to keep the Ctrl pressed.
;; I don't like vim but I'd like some simple one button navigation
;;
;; For a while, I used god-mode for that but its purpose is quite different
;; which sometimes caused some weird behaviour when I had it enabled.
;; Plus, some shortcuts simply aren't improved by this (e.g. C-M-f).
;; So I decided to write my own minor mode specifically for navigation *I*
;; need.
;;
@Nondv
Nondv / stupid-lisp-interpreter.clj
Last active March 31, 2025 20:35
A simple lisp POC implemented in clojure. Dynamically bound. Lambdas can receive code unevaluated. Written just to prove a point LOL
(comment
;; To run code from the file:
(stupid-eval
'()
(read-string (slurp "code.lisp")))
)
(declare stupid-eval)
(defn third [lst]
@Nondv
Nondv / config.ru
Created August 10, 2020 22:37
Simple config.ru
# frozen_string_literal: true
require_relative 'app'
# or any callable object e.g. a lambda
run Sinatra::Application
@Nondv
Nondv / multiple_changes_spec.rb
Last active January 28, 2019 10:10
RSpec multiple changes
require 'rspec/autorun'
RSpec.describe 'Multiple changes' do
subject do
proc do
a << 123
a << 456
b[:key] = 789
end
end
@Nondv
Nondv / .rubocop.yml
Created March 3, 2018 20:09
My rubocop config
AllCops:
DisplayStyleGuide: true
ExtraDetails: true
UseCache: false
Exclude:
# These files are generated automaticaly
- 'bin/**/*'
- "db/schema.rb"
# I think 80 is kinda obsolete. Nowdays we can easily read 120+ chars
@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[]) }
@Nondv
Nondv / my-regexp-for-url.rb
Created September 7, 2016 14:35
My regexp for URL
proto = '(https?://)'
domain = '([\w\-\.]+\w)'
path = '((/[\w\-]*)+)'
format = '(\.\w*)'
params = '(\?[^\n]*)' # whatever except \n
re = Regexp.new("\\A#{proto}#{domain}(#{path}#{format}?)?#{params}?\\z")
# ==> /\A(https?:\/\/)([\w\-\.]+\w)(((\/[\w\-]*)+)(\.\w*)?)?(\?[^\n]*)?\z/
@Nondv
Nondv / rotate_sequence.clj
Last active April 18, 2017 21:26
[4clojure.com] 44. Rotate sequence
; Write a function which can rotate a sequence in either direction.
;
; (= (__ 2 [1 2 3 4 5]) '(3 4 5 1 2))
; (= (__ -2 [1 2 3 4 5]) '(4 5 1 2 3))
; (= (__ 6 [1 2 3 4 5]) '(2 3 4 5 1))
; (= (__ 1 '(:a :b :c)) '(:b :c :a))
; (= (__ -4 '(:a :b :c)) '(:c :a :b))
; (= (__ -4 '(:a :b :c)) '(:c :a :b))
#(let [r (mod %1 (count %2))] (flatten [(drop r %2) (take r %2)]))