Skip to content

Instantly share code, notes, and snippets.

View rvanlieshout's full-sized avatar

Rene van Lieshout rvanlieshout

View GitHub Profile
scope :between, lambda { |start_date, end_date|
joins(sanitize_sql_array(["INNER JOIN clocks clocks_between ON clocks_between.shift_id = shifts.id AND clocks_between.datetime BETWEEN (? AND ?)", start_date, end_date]))
}
@rvanlieshout
rvanlieshout / description.txt
Created February 21, 2012 10:10
Filter scope
Save filter_scope.rb in your lib/ and make sure you lib/ is in your autoload path (I beleive that's default). Then add the following statement in your model:
include FilterScope
Now you're able to use .filter on your model:
Booking.filter(params[:search], [:name, :company, :site])
$.fn.observe = function(time, callback) {
return this.each(function() {
var form = $(this)
var serialized = form.serialize();
setInterval(function() {
if (serialized != form.serialize()) {
serialized = form.serialize();
callback.call(form);
}
validates :name, :presence: true, unless: :password_or_email_changed?
private
def password_or_email_changed?
password_changed? || email_changed?
end
require 'singleton'
class PhoneLogger
include Singleton
def self.set_file(logfile)
PhoneLogger.instance.set_file(logfile)
end
def set_file(logfile)
irb(main):019:0> Dir.mkdir "/var/www/vhosts/menuezorderstest.nl/rails/shared/upload/Orders/760/Links"
=> 0
= semantic_form_for @article, html: { class: 'form-horizontal' } do |f|
= f.inputs do
= f.input :name
= f.input :customer unless params.include?(:customer_id)
= f.input :number
= f.input :unit_price, as: :currency
= f.input :comments
= f.actions do
= f.action :submit, button_html: { class: 'btn btn-primary' }
odin git:(master) git remote show origin
* remote origin
Fetch URL: git@private:odin
Push URL: git@private:odin
HEAD branch: master
Remote branches:
HEAD tracked
feature-2023-multi-download tracked
feature-2062 tracked
feature-2064 tracked
link_to :sort => column, :direction => direction do
[
title,
tag(:span, :class => (direction == "asc" ? "glyphicon glyphicon-chevron-up" : "glyphicon glyphicon-chevron-down"))
].inject(&:+)
end
@rvanlieshout
rvanlieshout / time_registrations with date, grouped per month.sql
Last active August 29, 2015 14:02
Query to get unique time ranges in MySQL. Next up: see if this can be refactored
mysql> select * from intervals;
+----+----------+----------+
| id | start | end |
+----+----------+----------+
| 1 | 15:30:00 | 16:20:00 |
| 2 | 10:00:00 | 13:00:00 |
| 3 | 15:00:00 | 16:09:00 |
| 4 | 11:00:00 | 14:00:00 |
| 5 | 16:20:00 | 16:30:00 |
| 6 | 09:00:00 | 14:00:00 |