Ubuntu touchpad problem

2018 06 16 No Comments

When I install Kubuntu to my computer, unfortunately touchpad was not working. Tried a few ways and this way worked for me. (Xiaomi notebook pro)

sudo apt remove xserver-xorg-input-synaptics xserver-xorg-input-evdev
sudo apt install xserver-xorg-input-libinput

After then sudo vim /etc/X11/xorg.conf.d/30-touchpad.conf
Type these inside vim editor:

Section "InputClass"
    Identifier "touchpad"
    Driver "libinput"
    MatchIsTouchpad "on"
    Option "Tapping" "on"
EndSection

And press ESC, then :wq

Source.

WordPress üyelere özel içerik için kısa kod

2018 06 07 No Comments

Bazen üyelik sistemi ile çalışan wordpress sitelerinde, site sahipleri sadece üye girişi yapan kullanıcılara özel içerik göstermek isteyebilir. Bunu için kısa kod kullanmak en mantıklısıdır.

Yazı içerisinde “ozel” kısa kodunu kullanarak bazı içerikleri gizleyebilirsiniz.
Mesela:

[ozel] indirme linkleri vs burada [/ozel] 

Kısa kodu aktif etmek için temanızın functions.php dosyasını açın ve

<?php

den sonra ekleyin:

function uye_ozel_shortcode($atts, $content = null) {

   if(is_user_logged_in()) {
     return $content;
   } else {
     return '<a class="giris-yap" href="'.wp_login_url( get_permalink() ).'">Bu içeriği görmek için giriş yapmalısınız..</a>';
   }
}

add_shortcode('ozel', 'uye_ozel_shortcode');

Else bloğundan sonra içeriği düzenlemek size kalmış.

CSRF token with Selmer, Ring

2018 05 29 No Comments

Firstly install Selmer and Ring. Here are my project.clj

(defproject test "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :min-lein-version "2.0.0"
  :resource-paths ["public" "resources" "templates"]
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [compojure "1.5.1"]
                 [ring/ring-defaults "0.2.1"]
                 [mysql/mysql-connector-java "5.1.32"]
                 [yesql "0.5.3"]
                 [selmer "1.11.7"]
                 [org.clojure/tools.namespace "0.2.11"]
                 [proto-repl "0.3.1"]
                 [proto-repl-charts "0.3.1"]
                 ]

  :plugins [[lein-ring "0.12.4"]]
  :ring {:handler test.handler/app}
  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [ring/ring-mock "0.3.0"]]}})

After that, create crsf-token as tag to use in selmer template engine.
(more…)

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"

add_handler CSRF.new(
  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
  else
    "No token!"
  end
end

Kemal.run

Create a function to use it in templates
(more…)

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

Hello
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 = Crinja.new
c.loader = Crinja::Loader::FileSystemLoader.new("src/views/")

c.functions << Crinja.function({:str => ""}, :Markdown) do
  Markdown.to_html(arguments[:str].to_s)
end

To use it:

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

Enjoy.

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

Hello
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 = File.new()
	if file.open("user://shared_pref.sav", File.WRITE) != 0:
	    print("Error opening file")
	    return
	
	# Save the dictionary as JSON (or whatever you want, JSON is convenient here because it's built-in)
	file.store_line(to_json(data))
	file.close()


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

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

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

Here you are ready to save values to database:

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

Enjoy..

Godot Engine Android testing & publishing

2018 04 21 No Comments

Hey
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

Firstly

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 {
    StackNavigator,
} from 'react-navigation';
  

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

export default App;

First.js

import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  Button
} 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 (
		<Button
		  title="Go second"
		  onPress={() =>
			navigate('Second', { name: 'test' })
		  }
		/>
	  );
	}
}


export default First;

Second.js

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

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


export default Second;

Good luck.