Skip to content

Instantly share code, notes, and snippets.

View samilkorkmaz's full-sized avatar

Şamil Korkmaz samilkorkmaz

  • Ankara / Turkey
View GitHub Profile
@samilkorkmaz
samilkorkmaz / checkWithGPT4.php
Last active November 11, 2023 07:56
Check if a message contains email or phone number using OpenAI GPT-4 model
<?php
//Blog post: https://mentoringcomputer.blogspot.com/2023/11/detecting-phone-number-and-email-in.html
// Your OpenAI API key
$apiKey = 'your-api-key';
$user_data_list = [
[
'user_message' => "şunu dene beşyüzotuz sonra bakarız",
'containsEmail' => false,
@samilkorkmaz
samilkorkmaz / checkWithDaVinci.php
Last active November 4, 2023 17:55
Check if a message contains email or phone number using OpenAI API DaVinci model
<?php
//This code was generated with chatGPT4
//DaVinci model does not performa well. For a better solution use gpt-4 (see https://gist.github.com/samilkorkmaz/8a94c3e5caf8403d719566b251ebc40c)
$api_key = 'your-api-key';
$model = 'text-davinci-003';
$endpoint = 'https://api.openai.com/v1/engines/'.$model.'/completions';
// The user message you want to check
@samilkorkmaz
samilkorkmaz / handleCarriageReturn.cpp
Last active November 3, 2023 11:45
Handle carriage return
//blog post: https://simulinkforsoftwareengineers.blogspot.com/2023/11/handling-left-over-carriage-return.html
#include <iostream>
#include <string>
bool isCarriageReturn(const char c) {
return c == '\r';
}
int main() {
std::string line = "\r1.2\r4.56";
@samilkorkmaz
samilkorkmaz / index.php
Last active July 26, 2023 08:12
PHP server
//To run from terminal, cd into folder containing index.php: php -S localhost:8000
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// The request is using the POST method
$received_data = json_decode(file_get_contents('php://input'), true);
header('Content-Type: application/json');
echo json_encode(array('ticketID' => 5));
} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
// The request is using the GET method
if (isset($_GET['method'])) {
@samilkorkmaz
samilkorkmaz / whatsapp.html
Last active June 3, 2023 18:54
Floating whatsapp button on the bottom left of web page
<!DOCTYPE html>
<html>
<head>
<style>
.floating-whatsapp-button {
position: fixed;
bottom: 20px;
left: 20px;
cursor: pointer;
z-index: 9999;
@samilkorkmaz
samilkorkmaz / simpleCorruptAndChecksum.cpp
Last active April 24, 2023 05:40
Simple corruption and checksum
// Simple corruption and checksum
// Reference: https://www.youtube.com/watch?v=q-BvQgZVRGA&ab_channel=JacobSorber
// Şamil Korkmaz, April 23rd, 2023
#include <iostream>
#include <string.h>
const char* corrupt(const char* msg, size_t nBits) {
char* result = strdup(msg);
for (size_t i = 0; i < nBits; i++) {
int rbyte = rand() % strlen(msg);
@samilkorkmaz
samilkorkmaz / customPropDemo.py
Last active January 30, 2023 12:56
Blender 3.5 custom property demo
# Blender 3.5 custom property demo
# Modifed from https://docs.blender.org/api/current/bpy.props.html#operator-example
# Şamil Korkmaz, January 2023
import bpy
#Button
class OBJECT_OT_property_example(bpy.types.Operator):
bl_idname = "object.property_example"
bl_label = "Show property values in console"
@samilkorkmaz
samilkorkmaz / serializationDemo.cpp
Last active January 11, 2023 11:36
C++ simple serialization demo by converting struct to char (byte) array
//C++ simple serialization demo, converting struct to char (byte) array and back.
//Şamil Korkmaz, January 2023
#include <iostream>
#include <string.h> //for memcpy
typedef struct {
int d;
int i;
} MY_DATA;
@samilkorkmaz
samilkorkmaz / patternMatch.py
Last active January 3, 2023 13:52
Pattern searching with finite automata
# https://www.geeksforgeeks.org/finite-automata-algorithm-for-pattern-searching/
# Finite Automata pattern searching
# Automatically generates transition functions for input pattern string
# Jan 2023
def getNextState(pat, lenPat, state, c):
# https://www.youtube.com/watch?v=x8PSF9IJIhc&ab_channel
# If the character c is same as next character in pattern, increment state
if state < lenPat and c == pat[state]: return state + 1
# Find longest string where prefix == suffix
@samilkorkmaz
samilkorkmaz / shortestPathDijkstra.cpp
Last active December 30, 2022 06:43
C++ shortest path for a weighted adjaceny list using Dijkstra's algorithm
//Code generated by chatGPT, updated by Şamil Korkmaz, December 2022
#include<iostream>
#include<vector>
#include<queue>
#include<climits>
#include<algorithm>
//Dijkstra's algorithm to find shortest paths between source node and all other nodes
//source: Start node. Nodes are expressed as integers, e.g. 0, 1, ..., nNodes