Skip to content

Instantly share code, notes, and snippets.

@arkiver
arkiver / rails-jsonb-queries
Created January 13, 2021 19:15 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
debug_str = "params: #{params}, current_employee: #{employee.try(:id)}"
Appsignal.send_exception(e, debug_text: debug_str)
@arkiver
arkiver / replace.pl
Last active March 22, 2016 19:12
Replace all occurrences of and with && in all ruby files in current directory
perl -pi -w -e 's/ and/ &&/g;' *.rb
# Destructive! Use carefully.
# merged branches
((`git branch --merge master`).strip!.split(' ') - ['master', 'release']).map{ |b| `git branch -D "#{b}"; git push origin :"#{b}"` }
# All local branches
((`git branch`).strip!.split(' ') - ['master', 'release', 'development']).map{ |b| `git branch -D "#{b}"; git push origin :"#{b}"` }
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
irb(main):012:0> Date.today
=> Thu, 09 Jul 2015
irb(main):013:0> Date.tomorrow
=> Sat, 11 Jul 2015
irb(main):014:0> Date.today.tomorrow
=> Fri, 10 Jul 2015
@arkiver
arkiver / auto_scroll.js
Created March 13, 2014 11:07
Browse twitter/facebook handsfree :)
// run this in your browser's console
setInterval(function(){window.scrollBy(0, 1), 4000 })
// not well tested
@arkiver
arkiver / no-of-ele.lisp
Last active August 29, 2015 13:56
Return the no of elements in a list
(defun no-of-ele (lst)
"Return the no. of elements in a list"
(if (endp lst)
0
(progn (+ 1 (no-of-ele (rest lst))))
)
)
;; CL-USER> (no-of-ele '(1 2 3))
;; 3
@arkiver
arkiver / nth_element.lisp
Last active August 29, 2015 13:56
Purely recursive funtion to fetch nth element of list
(defun elek (lst n)
(if (= n 0)
(progn
(car lst))
(elek (rest lst) (- n 1))
)
)
;; CL-USER> (elek '(1 2 3 4) 2)
;; 3
@arkiver
arkiver / 1_last_of_list.lisp
Last active August 29, 2015 13:56
Simple implementation(s) for finding last element from a list using Common Lisp.
(defun last-of-list (l)
"Returns last element of a list"
(nth (- (list-length l) 1) l))