Skip to content

Instantly share code, notes, and snippets.

@nick1123
nick1123 / gist:8602628
Created January 24, 2014 18:01
Should trend builder ["rollup"]["pillars"]["activity"]["percent_of_goal_met"] exceed 100.0?
{"rollup"=>
{"total_points"=>3490,
"pillars"=>
{"activity"=>
{"points"=>2400, "percent_of_goal_met"=>400.0, "percent_of_total"=>68.8},
@nick1123
nick1123 / gist:8047081
Created December 19, 2013 22:08
riak vm
==> cat dev1/etc/vm.args
## Name of the riak node
-name dev1@127.0.0.1
## Cookie for distributed erlang. All nodes in the same cluster
## should use the same cookie or they will not be able to communicate.
-setcookie riak
## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
## (Disabled by default..use with caution!)
@nick1123
nick1123 / gist:8047048
Created December 19, 2013 22:06
riak app.config
==> cat dev1/etc/app.config
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
[
%% Riak Client APIs config
{riak_api, [
%% pb_backlog is the maximum length to which the queue of pending
%% connections may grow. If set, it must be an integer >= 0.
%% By default the value is 5. If you anticipate a huge number of
%% connections being initialised *simultaneously*, set this number
@nick1123
nick1123 / tournament_matches.rb
Created October 16, 2013 20:00
tournament matches
# Returns an array of matches that occur during the tournament and have a
# game_type of 100
def matches
values = Match.where(:game_type => ::Match::GAME_TYPE_TRN).where(
"starts_at >= ? and starts_at < ?", self.start_time, self.end_time).order(
"id ASC")
# Limit matches to max rounds
if self.rounds.present?
values = values[0..(self.rounds.to_i - 1)]
@nick1123
nick1123 / nokogiri_troubles.rb
Created September 11, 2013 19:36
Strange behavior using Nokogiri xpath
xml = '<?xml version="1.0" encoding="utf-8"?><mdx version="4.0" xmlns="responseSimple" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></mdx>'
parsed = Nokogiri.parse(xml)
parsed.xpath('/mdx').present?
# => false
xml = '<?xml version="1.0" encoding="utf-8"?><mdx></mdx>'
parsed = Nokogiri.parse(xml)
parsed.xpath('/mdx').present?
# => true
s = "hello\xdf".force_encoding("ASCII-8BIT")
s.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "")