Skip to content

Instantly share code, notes, and snippets.

@janjiss
janjiss / gist:6364171
Created August 28, 2013 09:40
body media data
{
"days": [
{
"date": "20130806",
"sleepPeriods": [
{
"state": "LYING",
"duration": 7,
"minuteIndex": 317
},
def get_coordinates
if @branch.present?
@show_cities = Purchase.where(:branch = @branch)
@show_sale_points = Purchase.find(:all, :select => "DISTINCT sale_point")
@show_all_blanches = Purchase.find(:all, :select => "DISTINCT branch")
@show_sale_points = Purchase.where(:city => @city, :branch => @branch) if @city.present?
if @city.present? && @sales_point.present?
coordinates = Purchase.where(:city => @city, :branch => @branch, :sale_point => @sale_point)
@latitude = coordinates.first.latitude
@longitude = coordinates.first.longitude
describe Class do
before do
@kopejais = 1
end
context "Konteksts 1" do
before do
@konteksta_1_variablis = 2
end
it "should be 3" do
@janjiss
janjiss / gist:6078162
Created July 25, 2013 09:22
Active admin hack
MyModel.class_eval do
def to_param
id
end
end
require "pry"
require "grit"
COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def days_in_month(month, year = Time.now.year)
return 29 if month == 2 && Date.gregorian_leap?(year)
COMMON_YEAR_DAYS_IN_MONTH[month]
end
@janjiss
janjiss / gist:5860382
Created June 25, 2013 17:19
Programming language of "Dzintars"
#encoding: utf-8
definēt a
ja patiesi
drukāt "a"
citādi
drukāt "b"
beigas
priekš i iekš [1,2,3]
drukāt i
beigas
@janjiss
janjiss / gist:5705749
Created June 4, 2013 13:05
Implementation of Time.nowish
class Time
def self.nowish
time = self.now
minute = time.min > 30 ? 30 : 00
"#{time.hour.to_s}:#{minute.to_s} ish"
end
end
def lat=(lat)
@lat = lat
end
require 'spec_helper'
describe Terminal do
let(:terminal) {
Terminal.create(
:address => "Kuldiga, Grants iela 29, Latvija",
:type => "ATM"
)
}
@janjiss
janjiss / gist:5590974
Created May 16, 2013 11:06
Ruby now supports Chinese names in methods. LOL.
irb(main):011:0> def 新增三個(數)
irb(main):012:1> 數+3
irb(main):013:1> end
=> nil
irb(main):014:0> 新增三個(3)
=> 6