Skip to content

Instantly share code, notes, and snippets.

View otobrglez's full-sized avatar
🏗️
Building.

Oto Brglez otobrglez

🏗️
Building.
View GitHub Profile
@otobrglez
otobrglez / film_search.rb
Created August 29, 2014 19:19
ElasticSearch - Mapping / Settings example
module FilmSearch
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
mapping do
indexes "title", type: 'string', analyzer: 'snowball'
indexes "signing.starts_at", type: 'date', format: 'basic_date'
@otobrglez
otobrglez / FizzBuzz.cs
Last active August 29, 2015 14:06
FizzBuzz in C# with Mono for Friday
/*
By Oto Brglez - <otobrglez@gmail.com>
What is FizzBuzz? http://en.wikipedia.org/wiki/Fizz_buzz
Requirements: Mono & Make
Compile with: make
Run with: mono ./FizzBuzz.exe
*/
using System;
@otobrglez
otobrglez / FizzBuzz.cs
Created September 5, 2014 19:47
FizzBuzz in C# w/ bit of Linq and generics
using System;
using System.Linq;
using System.Collections.Generic;
public class FizzBuzz {
public static IEnumerable<String> FizzBuzzMe(int to){
return Enumerable.Range(1, to).Select(j =>
j % 3 == 0 && j % 5 == 0 ? "Fizz Buzz" : (
j % 3 == 0 ? "Fizz" : (
j % 5 == 0 ? "Buzz" : j.ToString()
@otobrglez
otobrglez / FizzBuzz.cs
Last active August 29, 2015 14:06
FizzBuzz in C# w/ bit of Linq and generics (v2)
using System;
using System.Linq;
using System.Collections.Generic;
public class FizzBuzz {
public static List<String> FizzBuzzMe2(int to){
List<String> list = new List<String>();
int i = 1;
for(; i<=to; list.Add(i.ToString()), i++);
@otobrglez
otobrglez / FizzBuzz.cs
Created September 6, 2014 08:48
FizzBuzz in C# w/ bit of Linq and generics (v3)
using System;
using System.Linq;
using System.Collections.Generic;
public class FizzBuzz {
public static List<String> FizzBuzzMe3(int to){
return Enumerable.Range(1, to).Select(i =>
new Dictionary<int, String>(){
{1, i.ToString()}, {5, "Buzz"}, {3, "Fizz"}, {3*5, "Fizz Buzz"}
}.Last(a => i % a.Key == 0).Value
@otobrglez
otobrglez / Application.scala
Created September 10, 2014 21:08
FizzBuzz in Scala w/ lists, tuples and magic
object Application {
def fizzBuzzMega(e: Int): List[String] = {
var big = (1 to e).toList.map (i => i.toString)
val m = List(
(3, ((1 to e).toList zip List.range(0, e+3, 3)).drop(1).map (_._2)),
(5, ((1 to e).toList zip List.range(0, e+5, 5)).drop(1).map (_._2)),
(3*5, ((1 to e).toList zip List.range(0, e+3*5, 15)).drop(1).map (_._2))
).map(p =>
p._2.map (n =>
big = big.updated(n-1,
@otobrglez
otobrglez / .bash_profile
Last active August 29, 2015 14:07
Open continuous integration server at current build from command line (w/ github/hub)
# Install https://github.com/github/hub
# Add alias to your ~/.bash_profile (or somewhere alike)
alias ci-open='open `hub ci-status -v | grep -oE "[^\ ]+$"`'
Use it with your normal workflow...
git push ...
ci-open
# and see your CI pass. ;)
@otobrglez
otobrglez / open_close_panels.haml
Created October 16, 2014 17:04
Collapsable Bootstrap Panels
- I18n.available_locales.each_with_index do |locale,i|
- ulocale = locale.to_s.underscore
- show_expanded = [:'en-US', I18n.locale].include?(locale)
.panel.panel-default{id: ulocale}
%a.panel-default{"data-toggle" => "collapse", "data-parent" => "##{ulocale}", "href" => "#panel-#{ulocale}"}
.panel-heading
.panel-title= CONFIG[:display_locales][locale]
@otobrglez
otobrglez / cache_buster_expression.rb
Created October 27, 2014 12:23
Regex - Anything before "cache-buster"
# Regular expression that
# 1. Finds host name
# 2. Finds path name
# 3. Ignores first optional numeric 'cache-buster' parameter
xp = %r{^http:\/\/([a-z0-9\.]+)\/([a-z_]+)\/(.*?)(?:\?|$)}
@otobrglez
otobrglez / rails-ujs-patch.js
Last active August 29, 2015 14:10
Patching Rails UJS
/*
When tinymce f* u over!
*/
jQuery.rails.href = function(element) {
var href = element.attr('href');
if(typeof(href) == "string") {
return href;
}