Skip to content

Instantly share code, notes, and snippets.

View kafkadev's full-sized avatar
🏠
Working from home

Gokhan Celik kafkadev

🏠
Working from home
View GitHub Profile
@kafkadev
kafkadev / vtt_to_srt.php
Created February 22, 2020 15:40 — forked from audinue/vtt_to_srt.php
Converts VTT to SRT.
<?php
/*
string vtt_to_srt(string $in)
*/
function vtt_to_srt($in) {
$in = preg_split('@(\r\n|\n)+@', trim($in));
$n = 1;
$out = '';
for ($i = 1; $i < count($in); $i += 2) {
$out .= $n++ . "\n";
@kafkadev
kafkadev / js-encode-decode.md
Created February 5, 2020 08:30 — forked from yidas/js-encode-decode.md
JavaScript HTML Entities Encode & Decode
@kafkadev
kafkadev / slugify.js
Created August 1, 2019 00:43 — forked from hagemann/slugify.js
Slugify makes a string URI-friendly
function slugify(string) {
const a = 'àáäâãåăæąçćčđďèéěėëêęğǵḧìíïîįłḿǹńňñòóöôœøṕŕřßşśšșťțùúüûǘůűūųẃẍÿýźžż·/_,:;'
const b = 'aaaaaaaaacccddeeeeeeegghiiiiilmnnnnooooooprrsssssttuuuuuuuuuwxyyzzz------'
const p = new RegExp(a.split('').join('|'), 'g')
return string.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
// create the function
DB::connection()->pdo->sqliteCreateFunction("REGEXP", "preg_match", 2);
// build a query
DB::table('tablename')->raw_where('REGEXP("#^[a-z]+$#iu", tablename.row)')->get();
@kafkadev
kafkadev / http.js
Created May 15, 2019 02:49 — forked from lukaszb/http.js
es6 http client using fetch
import 'whatwg-fetch'
import Auth from './Auth';
import Url from 'url-parse';
const API_URL = process.env.API_URL
const http = {
get: get,
getAuthed: getAuthed,
@kafkadev
kafkadev / gist:9509fec237a48ad0b2276e60cba6cc22
Created December 26, 2018 20:52 — forked from joshhartman/gist:2289649
Creating XML Using SimpleXML + DOMDocument Output Formatting and SHJS Syntax Highlighting
<?php
$rss = new SimpleXMLElement('<rss version="2.0"/>');
$channel = $rss->addChild('channel');
$item = $channel->addChild('item');
$item->addChild('title')->{0} = 'Convicts flood streets of Boston';
$item->addChild('link')->{0} = 'http://www.example.com/2012/04/convicts-flood-streets-of-boston/';
$item->addChild('description')->{0} = 'Summarize news story here.';
@kafkadev
kafkadev / html_form
Created November 14, 2018 09:08 — forked from zvineyard/html_form
PHP: Upload and Rename File
<form action="" enctype="multipart/form-data" method="post">
<input id="file" name="file" type="file" />
<input id="Submit" name="submit" type="submit" value="Submit" />
</form>
@kafkadev
kafkadev / nearby-coordinates.sql
Created November 10, 2018 07:30 — forked from statickidz/nearby-coordinates.sql
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
METHOD 1
This should roughly sort the items on distance in MySQL, and should work in SQLite.
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance.
---
SELECT *
FROM table
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC
@kafkadev
kafkadev / magento_filters.php
Created August 30, 2018 05:49
Magento 2 Mutliselect filters
public function helpFilter()
{
/*
Kullanımı:
Tema içerisinde :
$helpFilter->helpFilter();
$helpFilter = $this->helper('Kafkaca\CustomWidget\Helper\Data');
Modul İçinde:
@kafkadev
kafkadev / magento-repo-locations.csv
Created August 23, 2018 22:53 — forked from tegansnyder/magento-repo-locations.csv
Github Repos that contain Magento - listing location from owners profile (if available)
sailthru New York, NY sailthru/sailthru-magento-extension 2011-06-30 19:01:37 +0000 UTC
yireo Netherlands yireo/plg_magentoapi 2012-08-09 07:54:21 +0000 UTC
mferracioli São José do Rio Preto mferracioli/magento-pagseguro 2011-10-20 17:24:14 +0000 UTC
Vinai Germany Vinai/customer-activation 2012-07-20 06:21:41 +0000 UTC
jacquesbh Paris jacquesbh/jbh_connectas 2012-07-19 06:45:41 +0000 UTC
magento not found magento/magento2 2011-11-30 15:30:13 +0000 UTC
mollie Amsterdam, Netherlands mollie/Magento 2012-01-24 14:35:15 +0000 UTC
sheerid not found sheerid/sheerid-magento 2012-05-02 15:23:51 +0000 UTC
netz98 Mainz netz98/n98-magerun 2012-08-01 13:13:14 +0000 UTC
PayU Grunwaldzka 182, 60-166 Poznań PayU/plugin_magento 2012-05-16 20:04:10 +0000 UTC