Skip to content

Instantly share code, notes, and snippets.

View mindscratch's full-sized avatar

Craig Wickesser mindscratch

View GitHub Profile
@mindscratch
mindscratch / notes.md
Last active December 17, 2021 18:01
functional programming notes
@mindscratch
mindscratch / foo.go
Created December 7, 2013 04:18
go using underscores in front of import package names
// $GOPATH/src/foo/foo.go
package foo
import "fmt"
func init() {
fmt.Println("foo init")
}
func init() {
@mindscratch
mindscratch / _readme.md
Created September 26, 2013 12:15 — forked from shime/_readme.md

Having trouble installing the latest stable version of tmux?

Save yourself some time and run this little fellow!

Prerequisities

  • gcc
  • wget
@mindscratch
mindscratch / word_count.go
Created September 14, 2013 01:10
Using Go - count the number of times each word appears in a given string
package main
import (
"fmt"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
counts := make(map[string](int))
@mindscratch
mindscratch / good_ice_creams.scala
Created July 11, 2013 23:40
A nice example of using for/yield in Scala, copied from Learning Functional Programming without Growing a Neckbeard (http://www.youtube.com/watch?v=OOvL6QAxRK4)
def goodPairings(pies: List[Pie], iceCreams: List[IceCream]): List(Serving[Pie, IceCream]) {
for {
p <- pies
i <- iceCreams
var serving = new Serving(p, i)
if (serving.isGood)
} yield {
serving
}
}
@mindscratch
mindscratch / fake_server.js
Last active July 13, 2018 05:56
Fake server-side using [Sinon.JS](http://sinonjs.org/). Inspiration from this [presentation](http://emdin.info/r/sinon-talk/).
var srv = sinon.fakeServer.create();
srv.autoRespond = true; // server should automatically respond after a timeout
srv.autoRespondAfter = 500; // response timeout in milliseconds
srv.xhr.useFitlers = true; // tell Sinon that some requests should not be faked
// add a filter that will tell Sinon to allowa all requests to access the server
// except fitlers defined when calling Server#fake.
srv.xhr.addFilter(function(method, url, async, username, password) {
var fakedRequest = _.find(Server.fakedRequests, function(request) {
return request.method === method && request.regex.test(url);
#!/usr/bin/env ruby
# Usage:
# git clog # prints
# git clog -w # writes
#
# https://gist.github.com/2880525
module Clog
extend self
@mindscratch
mindscratch / secure_rails
Created February 25, 2013 10:07
Start WEBrick with SSL enabled. ## Usage bundle exec ruby script/secure_rails s -e <environment> -p <port>
#!/usr/bin/env jruby
%W{rails/command/server rack webrick webrick/https}.each { |lib| require lib }
ENV['HTTPS'] = 'on'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
@mindscratch
mindscratch / mongoid_close_connections.rb
Created February 14, 2013 14:26
Rack middleware to close Mongoid's connections to MongoDB. See https://github.com/mongoid/mongoid/issues/2369.
require 'mongoid'
class MongoidCloseConnections
def initialize(app)
@app = app
end
def call(env)
path = env['PATH_INFO'] || ''
begin

Capybara

save_and_open_page

Matchers

have_button(locator)