Skip to content

Instantly share code, notes, and snippets.

Murilo Pereira mpereira

Block or report user

Report or block mpereira

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View app.jsx
/** @jsx React.DOM */
'use strict';
var TodoApplication = React.createClass({
taskStatuses: {
all: 'all',
todo: 'todo',
done: 'done'
View core.cljs
(ns om-laboratory.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[clojure.string :as string]))
(defn index-of [coll val]
(first (keep-indexed #(if (= %2 val) %1) coll)))
mpereira / nested_map_value_path.clj
Created Feb 27, 2014
Finding the path of a node in a tree.
View nested_map_value_path.clj
(defn map-zip [m]
( #(or (map? %) (map? (nth % 1)))
#(seq (if (map? %) % (nth % 1)))
(fn [x children]
(if (map? x)
(into {} children)
(assoc x 1 (into {} children))))
(defn path [m value]
mpereira / gist:9574586
Last active Aug 29, 2015
Determine if a point is within a triangle
View gist:9574586
(defn point-in-triangle? [[px py] [[p0x p0y] [p1x p1y] [p2x p2y]]]
(let [n (* 0.5
(+ (* (- p1y) p2x)
(* p0y (+ (- p1x) p2x))
(* p0x (- p1y p2y))
(* p1x p2y)))
sign (if (neg? n) -1 1)
s (* sign
(+ (* p0y p2x)
(- (* p0x p2y))
$ curl -s '' -H 'Referer:' -H 'Cache-Control: no-cache' | python -mjson.tool
    "a": "22212872",
    "c": "92334638",
    "cand": [
View test_scrubble.rb
require 'test/unit'
require 'test/unit/ui/console/testrunner'
def scrubble(array)
array.dup.inject([]) do |scrubbled, element|
scrubbled << array.reject { |e| e == element }
class ScrubbleTest < Test::Unit::TestCase

If you want to do something like

Then the output should contain "\"bob saget\",1234123412"

This is the step definition you would probably write

Then /^the output should contain "(.*)$" do |text|
  Output.string.should be_include(text)
View madrugao_suplementos_whey_crawler.rb
# encoding: utf-8
# Copyright (C) 2011 by Murilo Pereira <>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
View with_index.rb
battle_cries = [{ king_leonidas: 'This is where we fight! This is where they die!' },
{ he_man: 'By the power of Greyskull... I have the powerrr!' },
{ sindel: 'You are pathetic and weak.' },
{ shang_tsung: 'Your soul is mine!' },
{ klingons: 'Today is a good day to die!' }]
def from_mortal_kombat?(battle_cry)
[:sindel, :shang_tsung].include?(battle_cry.keys.first)

Remove trailing whitespace, convert tabs to spaces and file format to unix (remove ugly ^M carriage returns) from files using a single command:

vim -es -c 'set et ts=2 | bufdo retab | %s/\s\+$//e | set ff=unix | w' -c 'q' FILES

You could get your FILES using find

vim -es -c 'set et ts=2 | bufdo retab | %s/\s\+$//e | set ff=unix | w' -c 'q' $(find scripts -name '*.sh' -type f)

If in doubt, ask man.

You can’t perform that action at this time.