Skip to content

Instantly share code, notes, and snippets.

View Kalimaha's full-sized avatar
🌒
not because they are easy, but because they are hard

Guido Barbaglia Kalimaha

🌒
not because they are easy, but because they are hard
View GitHub Profile
@Kalimaha
Kalimaha / MathUtils.scala
Created August 11, 2016 23:31
Exceptions Handling with Scala
package com.rea.core
import scala.util.Try
object MathUtils {
def divide(x: Integer, y: Integer): Option[Double] = {
if (y == 0) None
else Some(x / y)
}
@Kalimaha
Kalimaha / Server.scala
Created August 9, 2016 03:41
Simple HTTP Server in Scala implemented with http4s
import org.http4s.server.{Server, ServerApp}
import org.http4s.server.blaze._
import scalaz.concurrent.Task
import org.http4s._, org.http4s.dsl._
import org.http4s.server.syntax._
object Main extends ServerApp {
val helloService = HttpService {
case GET -> Root / "hello" / name =>
Ok(s"Hello, $name.")
@Kalimaha
Kalimaha / day_00.scala
Created July 12, 2016 08:50
30 Days of Code
object Solution {
def main(args: Array[String]): Unit = {
for (ln <- io.Source.stdin.getLines) println("Hello, World.\n" + ln)
}
}
@Kalimaha
Kalimaha / SpreadOperator.js
Created June 14, 2016 01:45
JavaScript Spread Operator
var a = [1, 2, 3];
var b = [...a, 2, 3]
console.log(b) /* [1, 2, 3, 4, 5, 6] */
var l1 = [
{id: 1, name: 'Guido'},
{id: 2, name: 'Simone'}
]
var l2 = [
...l1,
@Kalimaha
Kalimaha / _map_1859.html
Last active May 4, 2016 05:36
Leaflet Script
<script type="application/javascript">
/* Load GeoJSON file. */
$.getJSON('geojson/1859.geojson', function (result) {
/* Init variables. */
var geojson = result,
map_1859 = L.map('1859').setView([42.10, 12.50], 5),
opacity = 1.0;
@Kalimaha
Kalimaha / people.yml
Created April 24, 2016 06:20
Generate random fixtures in Ruby-on-Rails
<% 1000.times do |n| %>
user_<%= n %>:
first_name: <%= ['Bruce', 'Steve', 'Dave', 'Janick', 'Adrian', 'Nicko'].sample %>
last_name: <%= ['Dickinson', 'Harris', 'Murray', 'Gers', 'Smith', 'McBrain'].sample %>
<% end %>
@Kalimaha
Kalimaha / application_helper.rb
Created April 23, 2016 07:42
Application Helper - init Method
def init_redis
@redis = Redis.new(:host => Rails.configuration.x.redis.host,
:port => Rails.configuration.x.redis.port,
:password => Rails.configuration.x.redis.password) if @redis == nil
end
@Kalimaha
Kalimaha / development.rb
Created April 23, 2016 07:40
Development settings
Rails.application.configure do
# Other stuff
# Rails instance
config.x.redis.host = 'localhost'
config.x.redis.port = 6379
config.x.redis.password = nil
end
@Kalimaha
Kalimaha / application_controller.rb
Created April 23, 2016 07:00
Application Controller
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :initialize_helper
skip_before_filter :verify_authenticity_token
def initialize_helper
init_redis
@Kalimaha
Kalimaha / application_helper.rb
Last active April 23, 2016 04:07
Application Helper
module ApplicationHelper
attr_reader :redis
@redis = nil
def init_redis
@redis = Redis.new(:host => Rails.configuration.x.redis.host,
:port => Rails.configuration.x.redis.port,
:password => Rails.configuration.x.redis.password) if @redis == nil