Skip to content

Instantly share code, notes, and snippets.

View dgutov's full-sized avatar

Dmitry Gutov dgutov

View GitHub Profile
@dgutov
dgutov / gist:824260
Created February 13, 2011 00:03
js2-mode imenu listing for Backbone.js
Backbone / Events / bind
Backbone / Events / unbind
Backbone / Events / trigger
Backbone / Model
Backbone / Collection
Backbone / Controller
Backbone / History
Backbone / View
Backbone / sync / params / beforeSend
Backbone / sync / <definition-1>
@dgutov
dgutov / gist:824262
Created February 13, 2011 00:05
js2-mode imenu listing for Underscore.js
_ / <definition-1>
_ / forEach
_ / map
_ / inject
_ / foldr
_ / detect
_ / select
_ / reject
_ / all
_ / any
@dgutov
dgutov / gist:845449
Created February 26, 2011 18:12
js2-mode imenu listing for jquery.js
jQuery / <definition-1>
jQuery / prototype / init
jQuery / prototype / size
jQuery / prototype / toArray
jQuery / prototype / get
jQuery / prototype / pushStack
jQuery / prototype / each
jQuery / prototype / ready
jQuery / prototype / eq
jQuery / prototype / first
@dgutov
dgutov / gist:845451
Created February 26, 2011 18:13
js2-mode imenu listing for mootools-core-1.3-full-nocompat.js
typeOf
instanceOf
Function / prototype / overloadSetter
Function / prototype / overloadGetter
Function / from
Array / from / <definition-1>
Array / from / <definition-2>
Number / from
String / from
Type / <definition-1>
@dgutov
dgutov / gist:1274520
Created October 10, 2011 02:35
ruby-indent-line advice for closing paren
(defadvice ruby-indent-line (after unindent-closing-paren activate)
(let ((column (current-column))
indent offset)
(save-excursion
(back-to-indentation)
(let ((state (syntax-ppss)))
(setq offset (- column (current-column)))
(when (and (eq (char-after) ?\))
(not (zerop (car state))))
(goto-char (cadr state))
@dgutov
dgutov / single_recipient_smtp.rb
Created March 16, 2012 12:24 — forked from croaky/single_recipient_smtp.rb
Set staging environment email to go to a single email address you control in order to not accidentally send production email addresses staging data.
module SingleRecipientSmtp
def self.included(clazz)
clazz.class_eval do
cattr_accessor :single_recipient_smtp_settings
end
end
def perform_delivery_single_recipient_smtp(mail)
mail.to = single_recipient_smtp_settings[:to]
mail.cc = nil
@dgutov
dgutov / paginated_collection.js
Created April 18, 2012 00:47 — forked from io41/paginated_collection.js
Pagination with Backbone.js
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage');
typeof(options) != 'undefined' || (options = {});
this.page = 1;
typeof(this.perPage) != 'undefined' || (this.perPage = 10);
},
fetch: function(options) {
@dgutov
dgutov / find-unused-def.el
Last active April 6, 2021 07:20
Find unused definitions in Emacs Lisp
(defun check-next-def ()
(push-mark nil t)
(when (re-search-forward
(concat "(def\\(?:un\\|macro\\|subst\\|var\\|const\\) "
"\\(\\(?:\\sw\\|\\s_\\)+\\)")
nil 'move)
(save-excursion
(let ((name (match-string 1)))
(goto-char (point-min))
(unless (re-search-forward (concat "\\_<" name "\\_>") nil t 2)
@dgutov
dgutov / company-ac.el
Last active December 15, 2015 07:48
auto-complete -> company bridge
;;; -*- lexical-binding: t -*-
(defvar ac-prefix)
(defun company-backend-from-ac (source-alist)
(cl-labels ((call (key &rest args)
(let ((fn (cdr (assoc key source-alist))))
(when fn
(apply fn args)))))
(lambda (command &optional arg &rest ignore)
@dgutov
dgutov / isearch-use-region-when-active.el
Last active December 16, 2015 05:59
Make isearch default to the current selection
(defun isearch-use-region-when-active ()
(when (region-active-p)
(setq mark-active nil)
(setq isearch-lazy-highlight-last-string nil)
(isearch-yank-string
(buffer-substring (region-beginning) (region-end)))))
(add-hook 'isearch-mode-hook 'isearch-use-region-when-active)