Skip to content

Instantly share code, notes, and snippets.

@ericat
ericat / keybase.md
Created August 27, 2018 20:39
keybase

Keybase proof

I hereby claim:

  • I am ericat on github.
  • I am ericat (https://keybase.io/ericat) on keybase.
  • I have a public key whose fingerprint is 68D1 A1C7 F9CD C013 A437 F0A5 080E 12A4 A1EB 63F8

To claim this, I am signing this object:

var _ = require('underscore'); // es6 can import what we need
// will return a function
function required(field, value) {
return value || 'Value is required';
}
function minLen(value) {
return value.length >= 6 ? value : 'Value is too short';
}
'use strict'
var results = [];
function perm(list, memo) {
for(var i=0; i < list.length; i++) {
var current = list.splice(i,1)[0];
if(list.length === 0) {
var permutation = memo.concat(current);
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import nock from 'nock';
import expect from 'expect';
import sinon from 'sinon';
import * as actions from './actions';
import * as types from './constants';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
@ericat
ericat / .vimrc
Last active May 19, 2017 15:53
vim configuration
set nocompatible " be improved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" Plugins
Plugin 'VundleVim/Vundle.vim'
Plugin 'digitaltoad/vim-jade'
@ericat
ericat / Xpath vs CSS Selectors in Ruby
Created December 28, 2013 23:32
Quick benchmarking between Xpath and CSS selectors with Nokogiri.
require 'open-uri'
require 'nokogiri'
require 'benchmark'
url = 'http://stackoverflow.com/questions/8214299/xpath-or-css-parsing-faster-for-nokogiri-on-html-files'
page = Nokogiri::HTML(open(url))
Benchmark.bmbm do |parser|
parser.report('Xpath') { 1000.times do page.at_xpath('//div[@id="sidebar"]//a[@class="question-hyperlink"]').text end }
@ericat
ericat / tiny scrapers series
Created December 13, 2013 19:53
tiny scrapers series: nokogiri
require 'rubygems'
require 'nokogiri'
require 'open-uri'
url = 'http://www.greenmangaming.com/genres/action/'
doc = Nokogiri::HTML(open(url))
File.open("scrape.txt", 'w') { |f|
doc.xpath('//h2').each do |item|
f.write "#{item.text}\n"
@ericat
ericat / nokogiri sraping from XML
Created December 13, 2013 19:51
Scraping an XML file with Nokogiri
require 'nokogiri'
require 'rubygems'
doc = Nokogiri::XML(File.open("path-to-file-sitemap.xml"))
doc.xpath('//xmlns:loc').each do |item|
puts item.text
end
@ericat
ericat / mechanize SSL
Created December 13, 2013 19:50
Fix SSL verification problem with mechanize
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
page = agent.get('https://tradein.asda.com/Catalog/GetMakesForProductType?productTypeID=7')
puts page.content
@ericat
ericat / watir headless scraper
Created December 13, 2013 19:44
Watir headless for Linux - headless watir gem is only available for linux.
require 'rubygems'
require 'watir'
require 'headless'
class Watir_Scraper
def initialize(url)
@headless = Headless.new
@headless.start
@b = Watir::Browser.new
@b.goto(url)