Skip to content

Instantly share code, notes, and snippets.

@dejan
dejan / SimpleScalaConsumer.scala
Last active July 5, 2017 19:04
SimpleConsumer
package tailtopic
import org.apache.kafka.clients.consumer.KafkaConsumer
import java.util.Properties
import scala.collection.JavaConverters._
import org.apache.avro.generic.GenericRecord
object Main extends App {
val consumerProperties = {
val props = new Properties()
@dejan
dejan / gist:627d862a519b97d048b0
Created September 3, 2014 08:16
prime factors
import scala.collection.mutable.ListBuffer
object Factorization {
implicit class FancyInt(val n: Int) extends AnyVal {
def primeFactors(): List[Int] = {
var factor = 2
var number = n
var factors = new ListBuffer[Int]()
do {
@dejan
dejan / compression.scala
Created August 24, 2014 22:51
Scala challenge #1
// Solution to Pere's first Scala challenge
// by Dejan
object Compression {
// Drops element ++el++ and all its consecutive appearances in head of the list ++li++
def chop(li: List[Any], el: Any) = {
li dropWhile (_ == el)
}
// Eliminates consecutive duplicates of list elements
package main
// using asymmetric crypto/RSA keys
import (
"fmt"
"io/ioutil"
"log"
"net/http"
@dejan
dejan / WTF Rails
Last active December 23, 2015 04:48
[18] pry(main)> expense.errors.keys
=> []
[19] pry(main)> expense.errors[:something]
=> []
[20] pry(main)> expense.errors.keys
=> [:something] ### !!! so getter on L19 changed the state
[21] pry(main)> expense.errors.has_key? :something
@dejan
dejan / auto_html.html.haml
Created February 14, 2013 16:36
auto_html demo
- title = 'auto_html demo'
- content_for :title, title
.page-header
%h1
.pull-right
.btn-group
= link_to 'article', '/2010/08/15/auto_html', class: 'btn'
= link_to 'source', 'https://github.com/dejan/auto_html', class: 'btn'
@dejan
dejan / gist:3913203
Created October 18, 2012 16:51
SF CollectionSelectInput monkey patch
# This is a monkey patch for the SimpleForm issue (actually it's a Rails' collection_select issue)
# of adding attributes to select options. Downside is that you loose value/label_method options,
# but that's easily replacable by using map on the collection (and should be done in some decorator anyways).
# See here for more details about the issue: https://github.com/plataformatec/simple_form/issues/188
module SimpleForm
module Inputs
class CollectionSelectInput < CollectionInput
def input
@builder.select attribute_name, collection, input_options, input_html_options
end
@dejan
dejan / whatevers.css.scss
Created July 21, 2012 15:58 — forked from justinfrench/whatevers.css.scss
Bootstrap mixins
@import "twitter/bootstrap";
.whatever {
@extend .well;
}
@dejan
dejan / campfire-emoji.txt
Created October 19, 2011 14:40 — forked from bryanl/campfire-emoji.txt
campfire emoji
Surround these with : e.g. :calling:
+1
-1
bulb
calling
clap
cop
email
feet
@dejan
dejan / rmagick on snow leopard
Created April 12, 2010 12:03
rmagick on snow leopard
#!/bin/sh
# http://onrails.org/articles/2009/09/04/rmagick-from-source-on-snow-leopard
# install wget, which is cleverer than curl
# curl -O http://ftp.gnu.org/gnu/wget/wget-1.11.tar.gz
# tar zxvf wget-1.11.tar.gz
# cd wget-1.11
# ./configure --prefix=/usr/local
# make