Skip to content

Instantly share code, notes, and snippets.

View elvanja's full-sized avatar

Vanja Radovanović elvanja

View GitHub Profile
@elvanja
elvanja / stats_api.rb
Created January 24, 2014 12:15
Executing external API calls
# SOURCE:
# http://rubylearning.com/blog/2014/01/24/from-lousy-to-beautiful/
module StatsApi
require 'json'
require 'httparty'
require 'active_support/core_ext/string'
require 'jsonpath'
## Reader: note that @error is raised so that we can easily handle that in our parent methods...
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.0.0'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
package org.testfu.storm;
import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.LocalDRPC;
import backtype.storm.StormSubmitter;
import backtype.storm.generated.StormTopology;
import backtype.storm.tuple.Fields;
import storm.trident.TridentState;
import storm.trident.TridentTopology;
@elvanja
elvanja / deploy_discourse_to_heroku
Last active March 20, 2017 08:01
Helps deploy Discourse to Heroku with: * local asset precompiling * RedisCloud add-on * Autoscaler with Sidekiq add-on Details @ http://shcatula.wordpress.com/2013/07/08/deploying-discourse-to-heroku
#!/bin/sh
# http://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommited-changes
require_clean_work_tree () {
# Update the index
git update-index -q --ignore-submodules --refresh
err=0
# Disallow unstaged changes in the working tree
if ! git diff-files --quiet --ignore-submodules --; then
# MOTIVATION: As rails apps are growing, people are noticing the drawbacks
# of the ActiveRecord pattern. Several apps I have seen, and several
# developers I have spoken to are looking towards other patterns for object
# persistence. The major drawback with ActiveRecord is that the notion
# of the domain object is conflated with what it means to store/retrieve
# it in any given format (like sql, json, key/value, etc).
#
# This is an attempt to codify the Repository pattern in a way that would
# feel comfortable to beginner and seasoned Ruby developers alike.
#
@elvanja
elvanja / dm_spec.rb
Last active December 15, 2015 08:08
In memory Data Mapper example spec
require 'dm-mapper'
require 'data_mapper/support/veritas/adapter/in_memory'
class Person
attr_reader :id, :name
def initialize(attributes)
@id, @name = attributes.values_at(:id, :name)
end
end
# file 'fruit_mapper.rb'
class FruitMapper < DataMapper::Mapper
map :id, Integer
map :name, String
map :taste, String
end
# file 'fruit_mapper_spec.rb'
require 'fruit_mapper'
describe FruitMapper do
@elvanja
elvanja / pom.xml
Created January 20, 2013 16:48
Maven project definition for NodeJS common dependency.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme.test</groupId>
<artifactId>nodejs-dependency</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>nodejs-dependency</name>
<description>NodeJS Dependency Project - to be references in nodejs-test</description>
<packaging>jar</packaging>
@elvanja
elvanja / pom.xml
Created January 20, 2013 16:34
Maven project definition for NodeJS deployable project.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme.test</groupId>
<artifactId>nodejs-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>nodejs-test</name>
<description>NodeJS Test Project</description>
<packaging>jar</packaging>
require_relative '../../../spec/spec_helper_without_rails'
require_relative 'amazon_search_response_parser_crack_hashie'
response = OpenStruct.new(body: File.read('spec/fixtures/amazon_api_responses/search_response_multiple_items.xml'))
result = AmazonSearchResponseParser.new.parse(response)
tests_to_run = 100
start = Time.now
tests_to_run.times { AmazonSearchResponseParser.new.parse(response) }
nokogiri = Time.now - start