Skip to content

Instantly share code, notes, and snippets.

View aozisik's full-sized avatar

Ahmet Özışık aozisik

View GitHub Profile
@aozisik
aozisik / slugify.js
Created July 8, 2014 10:14
Slugify Javascript Function
// creates valid slugs from strings. replaces turkish characters correctly.
function slugify(string) {
var letters = { "İ":"i", "I":"i", "ı":"i", "Ş":"s", "ş":"s", "Ğ":"g", "ğ":"g", "Ü":"u", "ü":"u", "Ö":"o", "ö":"o", "Ç":"c", "ç":"c" };
string = string.replace(/[İIıŞşĞğÜüÇçÖö]/g, function(letter){ return letters[letter]; })
.toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
@aozisik
aozisik / ideal_text_color.js
Last active August 29, 2015 14:15
Ideal Text Color
/*
* Finds the ideal text color for legibility on the background color provided
* Example i/o: idealTextColor('#000000') -> #ffffff
*/
function idealTextColor(background) {
var r = background.substring(1, 3);
var g = background.substring(3, 5);
var b = background.substring(5, 7);
@aozisik
aozisik / CountryTableSeeder.php
Created July 10, 2015 11:14
Country Table Seeder for Laravel
<?php
use Illuminate\Database\Seeder;
class CountryTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
@aozisik
aozisik / HasMoneyFields.php
Created February 14, 2018 20:22
If you are using moneyphp in Laravel, you may find this trait useful for your Eloquent models.
<?php
namespace App\Concerns;
use Money\Money;
use Money\Currency;
trait HasMoneyFields
{
public function getAttributeValue($key)
{
@aozisik
aozisik / macos-mojave-php72-v8js.sh
Last active June 14, 2023 12:28
Installing PHP v8js on Ubuntu 18.04 Bionic or Mac OS Mojave (brew)
# This will retrieve v8 7.4.288.25 when installled
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/0a6171330678879285f2c566db9349da421d6f62/Formula/v8.rb
brew install v8.rb
brew list v8
# You will see this:
# /usr/local/Cellar/v8/7.4.288.25/bin/d8
# /usr/local/Cellar/v8/7.4.288.25/libexec/include/ (21 files)
# /usr/local/Cellar/v8/7.4.288.25/libexec/ (7 files)
@aozisik
aozisik / .php-cs.php
Created November 10, 2019 16:41
Swiftmade PHP CS Config
<?php
return PhpCsFixer\Config::create()
->setRules(array(
'@PSR2' => true,
'array_syntax' => array('syntax' => 'short'),
'combine_consecutive_unsets' => true,
'method_separation' => true,
'no_multiline_whitespace_before_semicolons' => true,
'single_quote' => true,
@aozisik
aozisik / flash.blade.php
Last active November 13, 2019 19:30
Laravel Flash Blade View
@if($message = Session::get('error'))
<div class="alert alert-danger">{{ $message }}</div>
@endif
@if($message = Session::get('errors'))
<div class="alert alert-danger">{{ $message->first() }}</div>
@endif
@if($message = Session::get('success'))
<div class="alert alert-success">{{ $message }}</div>
@aozisik
aozisik / XmlString.js
Last active July 8, 2020 08:17
Paw dynamically build simple XML string from key-value list
var XmlString = function() {
var wrapInTag = function(tagName, string) {
return "<" + tagName + ">" + string + "</" + tagName + ">";
};
var toTags = function(entries) {
var output = "";
for (var i = 0; i < entries.length; i++) {
if (!entries[i][2]) {
@aozisik
aozisik / .php_cs
Last active October 5, 2021 22:58
Swiftmade's php-cs-fixer (v2) config for Laravel
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$rules = [
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => ['=>' => null],
@aozisik
aozisik / github-transfer.rb
Created September 3, 2020 09:31
Ruby script to transfer multiple GitHub repos in one go
# How to use:
# 1- Fill in fromHandle, toHandle, personalAccessToken and repositories
# 2- Run this script from Terminal:
#
# ruby ./github-transfer.rb
#
# 3- There's no step 3.
require 'json'
require 'uri'
require 'net/http'