Skip to content

Instantly share code, notes, and snippets.

View btd's full-sized avatar

Denis Bardadym btd

  • AWS
  • Deutschland, München
View GitHub Profile
@btd
btd / fib.scala
Created October 16, 2011 14:16
One line fib numbers without recursion and scala.math
val fib = (n:Int) => (0 until n).foldLeft(0, 1) { (x, i) => (x._2, x._1 + x._2) }._1
@btd
btd / encoding.c
Created November 29, 2011 08:14
How can i understand file encoding
/*
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
* maintained 1995-present by Christos Zoulas and others.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice immediately at the beginning of the file, without modification,
@btd
btd / matcher.scala
Created December 5, 2011 16:54
How to find begin string not sub seq.
1. (s: String) => Pattern.compile(regex, flags).matcher(text)
2. region(pos, str.length).lookingAt
@btd
btd / numberLines.js
Created April 4, 2012 16:57
numberLines.js
function numberLines(node, isPreformatted) {
var nocode = /(?:^|\s)nocode(?:\s|$)/;
var lineBreak = /\r\n?|\n/;
var document = node.ownerDocument;
var li = document.createElement('li');
while (node.firstChild) {
li.appendChild(node.firstChild);
}
@btd
btd / jQuery.print.js
Created April 15, 2012 07:25
jQuery.print.js
// Create a jquery plugin that prints the given element.
jQuery.fn.print = function(){
// NOTE: We are trimming the jQuery collection down to the
// first element in the collection.
if (this.size() > 1){
this.eq( 0 ).print();
return;
} else if (!this.size()){
return;
}
@btd
btd / macro.scala
Created August 29, 2012 08:22 — forked from akshaal/macro.scala
Scala 2.10: annotated fields macro
/** Akshaal, 2012. http://akshaal.info */
import language.experimental.macros
import scala.reflect.macros.Context
import scala.annotation.Annotation
/**
* Macros for traversing over annotated elements.
*
* See http://www.akshaal.info/2012/08/scala-210-annotated-fields-macro.html for more information.
@btd
btd / diff.scala
Created February 11, 2013 09:27
Symbolic computation of differential
package book
object diff {
trait Expression
case class Const[A: Numeric](value: A) extends Expression {
override def toString = value.toString
}
case class Var(name: String) extends Expression {
# ls
alias ls="ls -G"
alias la="ls -a"
alias ll="ls -l"
alias rm="rm -iv"
alias mv="mv -iv"
alias cp="cp -iv"
alias cr="cp -R"
export PATH=/usr/local/bin:$PATH:/usr/local/share/npm/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
bind "set completion-ignore-case on"
#export PS1="\[\e[1;32m\]\u\[\e[m\]\[\e[0;36m\]@\[\e[m\]\[\e[1;31m\]\h\[\e[m\]\[\e[0;36m\]:\[\e[m\]\[\e[1;33m\]\w\[\e[m\]\n\[\e[1;37m\] \$ \[\e[m\]"
if [ -f ~/.bash_aliases ]; then