Skip to content

Instantly share code, notes, and snippets.

@tugrul
tugrul / slug.js
Created July 17, 2025 13:54
turkish url slug
function generateSlug(text) {
return text
.replace(/I/g, 'i')
.toLowerCase()
.replace(/[çÇ]/g, 'c')
.replace(/[ğĞ]/g, 'g')
.replace(/[ıİ]/g, 'i')
.replace(/[öÖ]/g, 'o')
.replace(/[şŞ]/g, 's')
.replace(/[üÜ]/g, 'u')
@tugrul
tugrul / readme.md
Created May 18, 2025 15:04
C++ Endianness Detection: A Comprehensive Guide

C++ Endianness Detection: A Comprehensive Guide

Endianness refers to the byte order used to represent multi-byte data types (like integers or floating-point numbers) in memory. In little-endian systems, the least significant byte is stored first, while in big-endian systems, the most significant byte is stored first. For instance:

  • Little-endian (x86 architecture): 0x01020304 → in memory as [0x04, 0x03, 0x02, 0x01]
  • Big-endian (network byte order): 0x01020304 → in memory as [0x01, 0x02, 0x03, 0x04]

Why Check Endianness?

Endianness can affect network programming, binary file formats, or when interfacing with hardware, making it important to detect the system's endianness in certain situations.

find = lambda number, max: len([n for n in (a/b for a,b in (((a*b),(a+b)) for a in range(1,max) for b in range(1, max)) if a != 0 or b != 0) if n == number])
print(find(7, 1000))
@tugrul
tugrul / LastThread.php
Created December 21, 2018 19:48
doctrine result proxy entity
<?php
namespace ForumBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class LastThread
* @package ForumBundle\Entity
*/
@tugrul
tugrul / agar.io.js
Created May 19, 2018 13:28
agar.io gamepad
(function(){
const canvas = document.getElementById('canvas');
let split = false;
let eject = false;
function loop() {
const width = window.innerWidth;
const height = window.innerHeight;
@tugrul
tugrul / slither.io.js
Created May 19, 2018 13:27
slither io gamepad
(function(){
let localGsc = 1;
function loop() {
const gamepad = navigator.getGamepads()[0];
if (!gamepad) {
console.log('gamepad not found');
@tugrul
tugrul / s3-archive.js
Created March 5, 2018 15:09
archive.org S3 like storage using Node.JS AWS API
const AWS = require('aws-sdk');
const s3 = new AWS.S3({
endpoint: 'http://s3.us.archive.org',
accessKeyId: 'yourkeyid', // set your access key id
secretAccessKey: 'youraccesskey', // set your access key
signatureVersion: 'v2',
s3ForcePathStyle: true
});
@tugrul
tugrul / payment.php
Last active January 11, 2018 12:09
Self Declared Unique ID
<?php
class Payment
{
public $id;
public $posId;
public $amount;
public $currency;
public function getOrderId()
@tugrul
tugrul / TurkishCharacter.java
Last active January 10, 2016 11:58
NetBeans XDebug breakpoint_set Problem
package tugrul;
import java.nio.charset.Charset;
import java.util.Locale;
public class TurkishCharacter {
public static void main(String[] args) {
Locale.setDefault(Locale.ENGLISH);
@tugrul
tugrul / arrayobject.php
Created June 17, 2015 15:52
PHP BUG [SPL]: __get method is not calling
<?php
class MyArrayObject extends \ArrayObject
{
public function offsetGet($index)
{
if (!parent::offsetExists($index)) {
parent::offsetSet($index, new MyArrayObject(array(), \ArrayObject::ARRAY_AS_PROPS));
}