Skip to content

Instantly share code, notes, and snippets.

View machisuji's full-sized avatar

Markus Kahl machisuji

  • OpenProject GmbH
  • Cardiff, Wales, UK
View GitHub Profile
module MyStuff
include TheirStuff
def their_method
raise "doesn't work"
end
propagate!
end
@machisuji
machisuji / report_result.rb
Created April 28, 2011 12:25
Override Method in Report::Result::Base
class Report::Result
class Base
def method_to_be_overriden # von mir hinzugefügte Methode
end
def group_by(...) # existierende Methode von Base
...
method_to_be_overriden # Stelle #1
@machisuji
machisuji / gist:968584
Created May 12, 2011 14:21
has_and_belongs_to_many - destory
activerecord (3.0.7) lib/active_record/associations.rb:1713:in `has_and_belongs_to_many_after_destroy_for_reporting_users'
activesupport (3.0.7) lib/active_support/callbacks.rb:416:in `_run_destroy_callbacks'
activerecord (3.0.7) lib/active_record/callbacks.rb:256:in `destroy'
activerecord (3.0.7) lib/active_record/transactions.rb:235:in `destroy'
activerecord (3.0.7) lib/active_record/transactions.rb:292:in `with_transaction_returning_status'
activerecord (3.0.7) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
activerecord (3.0.7) lib/active_record/transactions.rb:207:in `transaction'
activerecord (3.0.7) lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
activerecord (3.0.7) lib/active_record/transactions.rb:235:in `destroy'
app/controllers/topics_controller.rb:92:in `destroy'
<a title="Delete" onclick="if (confirm('Are you sure ?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'jGHPe2+3FHbgJ61m83Q/yvgFhp6YsvjObFBEbhJk6R4='); f.appendChild(s);f.submit(); };return false;" href="/cost_entries/351"><img src="/images/delete.png?1309255162" alt="Delete"></a>
@machisuji
machisuji / MyParentProject.scala
Created September 1, 2011 20:28
Generating documentation for all projects
class MyParentProject(info: ProjectInfo) extends ParentProject(info) {
lazy val core = project("core", "mpp-core", new Core(_))
// ... more sub projects
lazy val docs = project("docs", "docs", new Docs(_), core /*, ... */)
def concatPaths[T](s: Seq[T])(f: PartialFunction[T, PathFinder]): PathFinder = {
def finder: T => PathFinder = f orElse { case _ => Path.emptyPathFinder }
(Path.emptyPathFinder /: s)(_ +++ finder(_))
b_ a d g
c d f g a
d c f g a f g
a d d f f d c d a ???
object Hello extends App {
val echo = new Echo with TcpConnection {
val host = args.drop(1).headOption getOrElse "localhost"
val port = args.drop(2).headOption.map(_.toInt) getOrElse 80
}
val msg = args.headOption getOrElse "Hallo Welt!"
Client.run(echo) { echo =>
val (text, letters) = echo.echo(msg)
println("\"%s\" contains %d letters.".format(text, letters))
// construct the viewer.
osgViewer::Viewer viewer;
@machisuji
machisuji / connection.scala
Created November 23, 2011 20:23
overriding abstract methods in Scala
trait Connection {
def in: InputStream
def out: OutputStream
}
trait Buffer extends Connection {
abstract override lazy val in = new BufferedInputStream(super.in) // overriding in, which is abstract
}
trait TcpConnection extends Connection {
@machisuji
machisuji / extr.scala
Created November 26, 2011 12:16
matching against a PushbackInputStream
object extr {
trait Message[T] {
def read(in: PushbackInputStream): Option[T]
def tag(in: PushbackInputStream) = {
val byte = in.read
in unread byte
byte