Skip to content

Instantly share code, notes, and snippets.

@mahadirz
mahadirz / chatgpt.php
Created March 17, 2023 11:50
simple chatgpt prompt using php
<?php
$completion = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Your OpenAI API key
$apiKey = '';
// The message you want to send to OpenAI
$message = $_POST['message'];
foreign
did the gpd4 developer demo live stream
honestly it's kind of hard for me to
believe that this day is here open AI
has been building this technology really
since we started the company but for the
past two years we've been really focused
on delivering gpt4
that started with rebuilding our entire
training stack actually training the
@mahadirz
mahadirz / spark.log
Created January 29, 2022 13:20
MyAWSCredentialsProviderWithUri missing
Py4JJavaError: An error occurred while calling o100.json.
: com.amazon.ws.emr.hadoop.fs.shaded.com.google.inject.ProvisionException: Unable to provision, see the following errors:
1) Error in custom provider, java.lang.NoClassDefFoundError: MyAWSCredentialsProviderWithUri$1
at com.amazon.ws.emr.hadoop.fs.guice.EmrFSBaseModule.provideAmazonS3Lite(EmrFSBaseModule.java:112)
at com.amazon.ws.emr.hadoop.fs.guice.EmrFSBaseModule.provideAmazonS3Lite(EmrFSBaseModule.java:112)
while locating com.amazon.ws.emr.hadoop.fs.s3.lite.AmazonS3Lite
for field at com.amazon.ws.emr.hadoop.fs.s3n.S3NativeFileSystem.s3(S3NativeFileSystem.java:92)
while locating com.amazon.ws.emr.hadoop.fs.s3n.S3NativeFileSystem
while locating org.apache.hadoop.fs.FileSystem annotated with @com.amazon.ws.emr.hadoop.fs.shaded.com.google.inject.name.Named(value=s3n)
@mahadirz
mahadirz / read_mysql_binlog.py
Created January 23, 2022 04:35
mysq-binlog-tutorial
import traceback
import pendulum
import pymysql
from pymysql.protocol import MysqlPacket
from pymysqlreplication.binlogstream import MYSQL_EXPECTED_ERROR_CODES
from pymysqlreplication.constants import *
from pymysqlreplication.event import *
from pymysqlreplication.packet import BinLogPacketWrapper
from pymysqlreplication.row_event import TableMapEvent, UpdateRowsEvent, WriteRowsEvent, DeleteRowsEvent
@mahadirz
mahadirz / payload.py
Last active January 22, 2022 18:53
mysql_binlog_tutorial
# this is a partial code
# skip to 462
# https://dev.mysql.com/doc/internals/en/query-event.html
file_pointer = 462
print("==================")
print("file_pointer", file_pointer)
f.seek(file_pointer)
header = Header()
header.unpack(f.read(header_length))
file_pointer += header_length
@mahadirz
mahadirz / read_event_query_1.py
Created January 22, 2022 15:59
mysql-binlog-tutorial
import struct
import pendulum
class Header:
def __init__(self):
self.timestamp = 0
self.event_type = None
self.server_id = None
self.event_size = 0
@mahadirz
mahadirz / read_struct.py
Last active January 22, 2022 05:31
mysql_binlog_tutorial
import struct
with open("person.bin", 'rb') as f:
while True:
data = f.read(72)
if not data:
break
unpacked = struct.unpack('<II32s32s', data)
print(f"ID:{unpacked[0]} "
f"Age:{unpacked[1]} "
@mahadirz
mahadirz / struct_in_c.c
Last active January 22, 2022 05:23
mysql_binlog_tutorial
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
int id;
uint32_t age;
char firstName[32];
char lastName[32];
@mahadirz
mahadirz / read_event_descriptor.py
Last active January 22, 2022 15:46
mysql_binlog_tutorial
import struct
bin_log_file = "mysql-bin-changelog.000050.bin"
file_pointer = 0
with open(bin_log_file, 'rb') as f:
magic = f.read(4)
# 0xfe, 0x62, 0x69, 0x6e
assert magic == b"\xfe\x62\x69\x6e"
# or
@mahadirz
mahadirz / database_import.sql
Created January 10, 2022 01:26
binlog_tutorial
# credit to https://www.digitalocean.com/community/tutorials/working-with-json-in-mysql
CREATE DATABASE IF NOT EXISTS `e_store`
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
SET default_storage_engine = INNODB;
CREATE TABLE `e_store`.`brands`(
`id` INT UNSIGNED NOT NULL auto_increment ,
`name` VARCHAR(250) NOT NULL ,