Skip to content

Instantly share code, notes, and snippets.

config.active_record.whitelist_attributes = true
@qoobaa
qoobaa / gist:1301216
Created October 20, 2011 14:04
underscore
(defun activesupport-underscore (string)
"underscores string just like in ActiveSupport inflector"
(let ((case-fold-search nil))
(downcase
(reduce (lambda (string replacement)
(replace-regexp-in-string (car replacement) (cadr replacement) string))
'(("::" "/")
("\\([[:upper:]]+\\)\\([[:upper:]][[:lower:]]\\)" "\\1_\\2")
("\\([[:lower:][:digit:]]\\)\\([[:upper:]]\\)" "\\1_\\2")
("-" "_"))
start on startup
exec /usr/local/bin/scanner.rb
@qoobaa
qoobaa / gist:1319547
Created October 27, 2011 13:34
camelize
(defun activesupport-camelize (string &rest args)
"camelizes string just like in ActiveSupport inflector"
(and (= 0 (length args)) (setq args '(t)))
(reduce (lambda (string replacement)
(replace-regexp-in-string (car replacement) (cadr replacement) string))
'(("^." (lambda (match) (upcase match)))
("_." (lambda (match) (upcase (substring match 1))))
("/.?" (lambda (match) (concat "::" (upcase (substring match 1)))) string))
:initial-value string
:start (if (car args) 0 1)))
class UserMailer < ActionMailer::Base
# ...
def daily_news(user)
mail(to: user.email, subject: "Daily newsletter")
end
private
def accepts_delivery?(address)
#!/usr/bin/env ruby
pictures = ARGV.map(&:to_i).sort
desired_group_size = ENV["GROUP_SIZE"].to_i
min_distance, max_distance = pictures.each_cons(2).map { |a, b| b - a }.minmax
groups = pictures.map { |picture| [picture] }
# Calculates distance factor using linear function.
#
# 1.0 when distance == min_distance
(defun next-generation (board)
(loop for row being the elements of board using (index x) collect
(loop for col being the elements of row using (index y) collect
(next-cell-p x y board))))
(defun next-cell-p (x y board)
(let ((count (neighbours-count x y board))
(cell (cell-p x y board)))
(or
(and cell (or (= count 2) (= count 3)))
ack -oh '\bt\("([^"]*)".*:default => "([^"]*)"' --output="\$1: \\\"\$2\\\""
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Zla liczba argumentow"
else
for user in `who | cut -d' ' -f1 | uniq`; do
for group in `groups $user`; do
if [ $group == $1 ]; then
echo $user
fi
done
// state = {
// deal: {
// n: ["HA", "..."],
// e: ["DA", "..."],
// s: ["SA", "..."],
// w: ["CA", "..."]
// },
// vulnerability: "BOTH",
// dealer: "E",
// bids: ["PASS", "1C", "X", "..."],