Using Kemal CSRF handler with Crinja

2018 05 19 No Comments

I assume that you are using kemal, kemal-session and kemal-csrf. Require them and use add_handler to handle requests.

Default input name is authenticity_token so I used it.

require "kemal"
require "kemal-session"
require "kemal-csrf"

  allowed_methods: ["GET", "HEAD", "OPTIONS", "TRACE"],
  error: ->myerrorhandler(HTTP::Server::Context)

def myerrorhandler(env)
  if env.request.headers["Content-Type"]? == "application/json"
    {"error" => "csrf error"}.to_json
    "No token!"

Create a function to use it in templates

Crystal seo friendly url

2018 05 19 No Comments

Maybe someone needs it.

Markdown render in template side with Crinja – Crystal

2018 05 18 No Comments

In crystal ecr templates, we can use render markdown like this: <%= Markdown.to_html("# text") %>

But with crinja we cant do it as I see.

So I created template function.

require "markdown"

c =
c.loader ="src/views/")

c.functions << Crinja.function({:str => ""}, :Markdown) do

To use it:

{{ Markdown("# title")  | safe}}


Crystal code reloading with nodemon

2018 05 14 No Comments

I saw this solution in this link.

First install nodemon globally:
npm i -g nodemon

After install, run your main cr file:
nodemon --exec "crystal run" src/{YOUR_MAIN_FILE}.cr

In my computer (macbook early 2015 8/128), it works faster than sentry.

Ps: Nodemon doesn’t works with ecr templates, sentry works.

Godot Engine key-value based database

2018 04 22 No Comments

Here are you simple database for Godot Engine. I got inspired from this answer at godotengine qa.

func SetValue(key, value):
	var data = {key: value}
	var file =
	if"user://shared_pref.sav", File.WRITE) != 0:
	    print("Error opening file")
	# Save the dictionary as JSON (or whatever you want, JSON is convenient here because it's built-in)

func GetValue(key):
	var file =
	if not file.file_exists("user://shared_pref.sav"):
	    print("No file saved!")
	# Open existing file
	if"user://shared_pref.sav", File.READ) != 0:
	    print("Error opening file")
	# Get the data
	var data = {}
	data = parse_json(file.get_line())
	if data.has(key):
		return data[key]
		print(key, " [key] not assigned in saved_data")
		return 0

Save above file named … To use it import like this:

onready var Database = preload("res://").new()

Here you are ready to save values to database:

Database.SetValue("SomeValue", "test")
var foo = Database.GetValue("SomeValue")


Godot Engine Android testing & publishing

2018 04 21 No Comments

I am writing these informations as a note. If I forgot the steps, I can look at this page..

Firstly Editor > Manage Export Templates. Download and install, that’s it.

Secondly in Editor > Editor Settings set these values:
– adb (download android studio and set path)
– jarsigner executable (download from version 8 and set jarsigner path)
– debug keystore

Last step is to set window.

Go Project > Project Settings > Display > Window
– Scroll to Strect section
– Set mode 2d(2d because I am working on 2d game)
– Aspect=expand.

So you can test now on your phone and see result.

To run game on your phone, enable usb debugging in your phone and connect usb cable. There will be Android icon next to Play Scene button.

More Godot Engine posts will be came..
<3 Godot Engine Happy coding.

React Native navigation

2018 02 27 2 Comments


Install react-navigation

npm install react-navigation --save
react-native link

In App.js dont forget to import react-navigation

import React, { Component } from 'react';

import First from './First';
import Second from './Second';

import {
} from 'react-navigation';

const App = StackNavigator(
        First: { screen: First},
        Second: { screen: Second},
      initialRouteName: 'First',

export default App;


import React, { Component } from 'react';
import {
} from 'react-native';

import { NavigationActions } from 'react-navigation';

class First extends React.Component {
	static navigationOptions = {
	  title: 'First view',
	render() {
	  const { navigate } = this.props.navigation;
	  return (
		  title="Go second"
		  onPress={() =>
			navigate('Second', { name: 'test' })

export default First;


import React, { Component } from 'react';
import {
  View, Button
} from 'react-native';

class Second extends React.Component {
	static navigationOptions = {
	  title: 'Second',
	render() {
	  const { navigate } = this.props.navigation;
	  return (
		title="Go back"
		onPress={() => this.props.navigation.goBack()}

export default Second;

Good luck.

How I start to code CSS

2017 09 10 No Comments

Usually I am using these lines to start new project. It makes coding HTML easy.

/* ================== clearfix ================== */
.cf:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } .c
.cf { display: inline-block; }
* html .cf { height: 1%; }
.cf { display: block; }

/* ================== useful ================== */
.cb {clear:both}
.dib {display: inline-block;}
.db {display: block;}
.fl {float: left;}
.fr {float: right;}

/* ================== box sizing ================== */
*, *:before, *:after {
   -webkit-box-sizing: border-box;
   -moz-box-sizing: border-box;
   box-sizing: border-box;

*:focus {outline: none;}


Unity3d grey screen in Asset store and services tabs

2016 12 17 No Comments

In Unity 5.4 there is a bug. Both Assets store and services tabs are not working.I dont know everyone has this problem.

Solution is dead simple. Just undock the section windows. And restart Unity3d, because in services section it can be shown “You do not have permission for this action” error.

Here is the problem:


Unity3d DOTween creating sequence

2016 12 15 No Comments


DOTween is one of the popular plugins in the Asset Store. It makes easier creating tweens and animations. Besides the Unity’s animation engine, Dotween is simple and useful. You can create tweens both with script or inspector easily.

Here you are sequence example in with DOTween:

Sequence Test_Sequence = DOTween.Sequence();
Test_Sequence.Append(Icon.transform.DOScale (new Vector3 (1.4f, 1.4f, 0), 0.1f));
Test_Sequence.Append(Icon.transform.GetComponent<Image>().DOColor(, 0.1f));
mySequence.Append(Icon.transform.DOScale (new Vector3 (1f, 1f, 1f), 0.1f));

Test_Sequence.AppendCallback(() => {
	// this is callback
Test_Sequence.Play ();

For more examples click here.