Skip to content

Instantly share code, notes, and snippets.

View lukesarnacki's full-sized avatar

Łukasz Sarnacki lukesarnacki

View GitHub Profile
List<Product> products;
products = (from item in xdoc.Descendants("object")
select new Product()
{
Name = item.Element("name").Value,
Description = item.Element("description").Value
}).ToList();
<objects type="array">
<object>
<id type="integer">1</id>
<name>Śmietanka łaciata</name>
<description nil="true"/>
<company-name>Mlekpol</company-name>
<ingredients type="array">
<ingredient>
<id type="integer">1</id>
<number>E339</number>
class YmlLength
attr_accessor :data, :result
def initialize(path)
self.data = YAML::load_file(Rails.root.join(path)).to_a.flatten.last
self.result = ""
get_value(data)
end
@lukesarnacki
lukesarnacki / gist:3721654
Created September 14, 2012 12:30
ember example
.
class ActionDispatch::Session::JsonSerializer
def self.load(value)
JSON.load(value) + " and loaded"
end
def self.dump(value)
JSON.dump(value + " was dumped")
end
end
@db = ''
@user = ''
@password = ''
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'pg'
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
4 8
-2 -2 -3 1
3 0 1 3
1 3 -3 3
2 0 0 -2
0 0 2 1
2 2 2 3
1 2 1 3
3 2 3 3
3 0 3 3
class Maclaurin
attr_reader :x, :steps, :function
DERIVATIVE = {
"sin" => "cos",
"cos" => "-sin",
"-sin" => "-cos",
"-cos" => "sin",
"e" => "e"
@lukesarnacki
lukesarnacki / test.rb
Last active April 4, 2017 14:49
ActiveRecord inconsistency on changes method
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"