Skip to content

Instantly share code, notes, and snippets.

View mnylen's full-sized avatar

Mikko Nylén mnylen

  • Mikko Nylén Oy
  • Toijala
  • X @nylemi
View GitHub Profile
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
@mnylen
mnylen / OS X Snow Leopard
Created January 5, 2011 13:21
How to get RVM + Subversion Ruby Bindings to work
$ rvm use 1.8.7-p302
$ wget http://subversion.tigris.org/downloads/subversion-1.6.15.tar.gz
$ tar -xzf subversion-1.6.15.tar.gz && cd subversion-1.6.15
$ ./configure --with-ruby-sitedir=~/.rvm/rubies/ruby-1.8.7-p302/lib/ruby --without-berkeley-db
$ make swig-rb && make install-swig-rb
To test things out:
$ irb
ruby-1.8.7-p302 > require 'svn/client'
=> true

deny

deny is a simple DSL for doing authorizations in Ruby on Rails controllers. It follows the principle of default deny: all requests are denied unless explicitly permitted.

Usage

First, include the Deny module to your ApplicationController. This sets up the controller to deny all requests made.

express = require 'express'
assetManager = require 'connect-assetmanager'
app = express.createServer
app.use assetManager
var pressedKeys = {};
var tick = function(msDuration) {
gamejs.event.get().forEach(function(e) {
if (e.type == gamejs.event.KEY_DOWN) {
pressedKeys[e.key] = true;
} else if (e.type == gamejs.event.KEY_UP) {
delete pressedKeys[e.key];
}
});
# config/initializers/suppress_action_view_field_errors.rb
# The default form builder appends <div class="field_with_errors"> (or something similar)
# to all fields and labels for model attributes that have validation errors. Doesn't work
# so well with Bootstrap.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
"#{html_tag}".html_safe
end
val zip = new ZipStreamHelper(new ZipInputStream(...))
zip.rewindTo("hello.xml") { in =>
val parser = STaxParser()
val root = parser.fromInputStream(in)
}
@mnylen
mnylen / ScalatraFileUploadTests.scala
Created April 6, 2012 19:11
postMulti() helper for scalatra-test for making multipart/form-data requests. Useful when testing file uploads with scalatra-fileupload
import org.apache.commons.io.IOUtils
import org.eclipse.jetty.http.HttpHeaders
import org.eclipse.jetty.testing.HttpTester
import org.eclipse.jetty.io.ByteArrayBuffer
import util.DynamicVariable
import org.scalatra.test.ScalatraTests
import java.net.HttpCookie
import java.io.{ByteArrayOutputStream, FileInputStream, File}
trait ScalatraFileUploadTests extends ScalatraTests {
(ns porter-stemmer.test
(:gen-class))
(defn -main
[]
(dotimes [n 20000]
(println n)))
val resp = client
.prepareSearch(IndexName)
.setTypes(TypeName)
.setQuery(qb)
.addSort("id", SortOrder.ASC)
.execute()
.actionGet()
resp.getHits.getHits.map(hit =>
parse(hit.sourceAsString()).asInstanceOf[JObject]