Skip to content

Commit

Permalink
2024-07-17 17:10:59.444920 new snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardocerqueira committed Jul 17, 2024
1 parent 76093b9 commit 985f96f
Show file tree
Hide file tree
Showing 17 changed files with 483 additions and 824 deletions.
31 changes: 31 additions & 0 deletions seeker/report.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
--------------------------------------------------------------------------------
2024-07-17 17:10:59.444920
--------------------------------------------------------------------------------
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: snippet/Dockerfile
deleted: snippet/copilot-generate-inventory-data-python-excel.py
deleted: snippet/copilot-python-excel-customer-churn-dataset.py
deleted: snippet/copilot-python-fake-scores.py
deleted: snippet/create-socket-server.sh
deleted: snippet/deep_neural_network.py
modified: snippet/module_2_5.py
deleted: snippet/python-script-100-fake-customers-excel-SEED.py
deleted: snippet/test.py

Untracked files:
(use "git add <file>..." to include in what will be committed)
snippet/.bash_profile
snippet/API KEY 2 image in website.py
snippet/bacnet_grammar.py
snippet/check-cors.sh
snippet/check-gasp-tables.py
snippet/module2hard.py
snippet/module_tree_explorer.py

no changes added to commit (use "git add" and/or "git commit -a")

--------------------------------------------------------------------------------
2024-07-16 17:11:31.119487
--------------------------------------------------------------------------------
Expand Down
30 changes: 30 additions & 0 deletions seeker/snippet/.bash_profile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#date: 2024-07-17T16:48:03Z
#url: https://api.github.com/gists/913369d44d85a27790f1c6488625d46d
#owner: https://api.github.com/users/kartikkapatel

# laravel new-app
alias laravel="git clone -o laravel -b develop https://github.com/laravel/laravel.git"

alias artisan="php artisan"
alias migrate="php artisan migrate"
alias serve="php artisan serve"
alias dump="php artisan dump"
alias t="phpunit"

# Generators Package
alias g:c="php artisan generate:controller"
alias g:m="php artisan generate:model"
alias g:v="php artisan generate:view"
alias g:mig="php artisan generate:migration"
alias g:t="php artisan generate:test"
alias g:r="php artisan generate:resource"
alias g:s="php artisan generate:scaffold"
alias g:f="php artisan generate:form"

# Git
alias ga="git add"
alias gaa="git add ."
alias gc="git commit -m"
alias gp="git push"
alias gs="git status"
alias gl="git log"
149 changes: 149 additions & 0 deletions seeker/snippet/API KEY 2 image in website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#date: 2024-07-17T17:08:44Z
#url: https://api.github.com/gists/26176d2ec38dc76acf34704a46bef75a
#owner: https://api.github.com/users/me-suzy

import os
import re
from openai import OpenAI
import requests
from PIL import Image
import io

# Configurare OpenAI API
client = OpenAI(api_key='YOUR-KEY')

def generate_image_description(text):
try:
response = client.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": "Ești un expert în crearea de descrieri concise pentru imagini. Analizează textul dat și creează o descriere scurtă și clară pentru o imagine care să reprezinte esența întregului mesaj."},
{"role": "user", "content": f"Creează o descriere scurtă pentru o imagine care să reprezinte esența următorului text, în maxim 50 de cuvinte:\n\n{text}"}
]
)
description = response.choices[0].message.content.strip()
return description
except Exception as e:
print(f"Eroare la generarea descrierii imaginii: {e}")
return "Descriere temporar indisponibilă"

def generate_image(description):
try:
enhanced_prompt = f"""
Creează o imagine bazată pe următoarea descriere, fără a include text sau fraze scrise în imagine:
{description}
Instrucțiuni suplimentare:
- Nu include niciun fel de text, cuvinte sau litere în imagine.
- Concentrează-te pe reprezentarea vizuală a conceptelor și ideilor.
- Utilizează simboluri, forme și culori pentru a transmite mesajul.
- Asigură-te că imaginea este clară și ușor de înțeles fără text explicativ.
"""

response = client.images.generate(
model="dall-e-3",
prompt=enhanced_prompt,
size="1024x1024",
quality="standard",
n=1,
)
image_url = response.data[0].url
return image_url
except Exception as e:
print(f"Eroare la generarea imaginii: {e}")
return None

def generate_image_caption(description):
try:
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "Generează un scurt caption pentru o imagine bazată pe următoarea descriere. Caption-ul trebuie să fie concis și să reflecte conceptul de leadership sau performanță."},
{"role": "user", "content": description}
]
)
caption = response.choices[0].message.content.strip()
return caption
except Exception as e:
print(f"Eroare la generarea caption-ului imaginii: {e}")
return "Concept de performanță în leadership"

def download_and_resize_image(url, output_path):
response = requests.get(url)
img = Image.open(io.BytesIO(response.content))
img = img.resize((1024, 719), Image.LANCZOS)
img.save(output_path)
return output_path

def extract_article_content(content):
start_tag = '<!-- ARTICOL START -->'
end_tag = '<!-- ARTICOL FINAL -->'
pattern = re.compile(f'{re.escape(start_tag)}(.*?){re.escape(end_tag)}', re.DOTALL)
match = pattern.search(content)
if match:
return match.group(1)
return None

def clean_html(html_content):
clean_text = re.sub(r'<[^>]+>', '', html_content)
clean_text = re.sub(r'\s+', ' ', clean_text).strip()
return clean_text

def process_file(file_path, image_folder):
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()

article_content = extract_article_content(content)
if not article_content:
print(f"Nu s-a găsit conținut de articol în {file_path}")
return False

cleaned_content = clean_html(article_content)
description = generate_image_description(cleaned_content)
image_url = generate_image(description)

if image_url:
file_name = f"{os.path.splitext(os.path.basename(file_path))[0]}_image.jpg"
image_path = os.path.join(image_folder, file_name)
local_image_path = download_and_resize_image(image_url, image_path)

caption = generate_image_caption(description)

image_html = f'''
<br><br>
<div class="feature-img-wrap">
<img src="https://neculaifantanaru.com/images/{file_name}" alt="{description[:100]}" class="img-responsive">
<!-- <p class="image-caption">Ilustrație: {caption}</p> -->
</div>
'''

content = content.replace('YYY', image_html, 1)

with open(file_path, 'w', encoding='utf-8') as file:
file.write(content)

return True

return False

def main():
folder_path = 'd:\\1\\'
image_folder = 'd:\\1\\images\\'
os.makedirs(image_folder, exist_ok=True)
modified_files = []

for filename in sorted(os.listdir(folder_path)):
if filename.endswith('.html'):
file_path = os.path.join(folder_path, filename)
was_modified = process_file(file_path, image_folder)
if was_modified:
modified_files.append(file_path)

with open('api+rezumat.txt', 'w', encoding='utf-8') as file:
file.write("Fișiere modificate:\n")
for modified_file in modified_files:
file.write(f"{modified_file}\n")

if __name__ == "__main__":
main()
24 changes: 0 additions & 24 deletions seeker/snippet/Dockerfile

This file was deleted.

60 changes: 60 additions & 0 deletions seeker/snippet/bacnet_grammar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#date: 2024-07-17T16:57:43Z
#url: https://api.github.com/gists/1dd04ba34191cc1495ebd2cc33c580ff
#owner: https://api.github.com/users/stevedh


import lrparsing
from lrparsing import Keyword, List, Prio, Ref, THIS, Token, Tokens, Repeat

class BacnetParser(lrparsing.Grammar):

"**********" "**********" "**********" "**********" "**********"c "**********"l "**********"a "**********"s "**********"s "**********" "**********"T "**********"( "**********"l "**********"r "**********"p "**********"a "**********"r "**********"s "**********"i "**********"n "**********"g "**********". "**********"T "**********"o "**********"k "**********"e "**********"n "**********"R "**********"e "**********"g "**********"i "**********"s "**********"t "**********"r "**********"y "**********") "**********": "**********"
integer = "**********"="\-?[0-9]+")
decimal = "**********"="-?[0-9]+\.[0-9]+")
ident = "**********"="[a-zA-Z][a-zA-Z0-9\-\.\&\_]*")
context_tag = "**********"="\[[0-9]+\]")

definition = Ref("definition")
optional_bacnet_type = Ref("optional_bacnet_type")
bacnet_type = Ref("bacnet_type")

struct_element = T.ident + optional_bacnet_type | \
T.ident + T.context_tag + optional_bacnet_type
enum_element = T.ident + "(" + T.integer + ")" | "..."
integer_range = "(" + T.integer + ".." + T.integer + ")"
decimal_range = "(" + T.decimal + ".." + T.decimal + ")"
primative = Keyword("NULL") | Keyword("BOOLEAN") | Keyword("REAL") | \
Keyword("Unsigned") | Keyword("Unsigned8") | \
Keyword("Unsigned") + integer_range | \
Keyword("Unsigned16") | Keyword("Unsigned32") | \
Keyword("Unsigned64") | Keyword("INTEGER") | \
Keyword("INTEGER16") | Keyword("REAL") | \
Keyword("REAL") + decimal_range | \
Keyword("Double") | Keyword("OCTET") + Keyword("STRING") | \
Keyword("CharacterString") | \
Keyword("CharacterString") + "(" + Keyword("SIZE") + integer_range + ")" | \
Keyword("BIT") + Keyword("STRING") | \
Keyword("ENUMERATED") | Keyword("Date") | \
Keyword("Time") | Keyword("BACnetObjectIdentifier")

choice = Keyword("CHOICE") + "{" + List(struct_element, ",") + "}"
sequence = Keyword("SEQUENCE") + "{" + List(struct_element, ",") + "}"
sequence_of = Keyword("SEQUENCE") + Keyword("OF") + bacnet_type | \
Keyword("SEQUENCE") + Keyword("SIZE") + "(" + T.integer + ")" + Keyword("OF") + bacnet_type
enumeration = Keyword("ENUMERATED") + "{" + List(enum_element, ",") + "}"
bit_string = Keyword("BIT") + Keyword("STRING") + "{" + List(enum_element, ",") + "}"

bacnet_type = T.ident | primative | choice | sequence | \
sequence_of | enumeration | bit_string
optional_bacnet_type = bacnet_type | bacnet_type + Keyword("OPTIONAL")

definition = T.ident + "::=" + bacnet_type

START= Repeat(definition)
COMMENTS = Token(re="\-\-(?: "**********"


if __name__ == "__main__":
import sys
parse_tree = BacnetParser.parse(open(sys.argv[1], "r").read())
print(BacnetParser.repr_parse_tree(parse_tree))
69 changes: 69 additions & 0 deletions seeker/snippet/check-cors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#date: 2024-07-17T16:39:19Z
#url: https://api.github.com/gists/ee052b966c950b6d040b0c7fa47633d6
#owner: https://api.github.com/users/mpo-vliz

#! /bin/bash

# endpoints
ENDPOINTS=("https://id.cabi.org/PoolParty/sparql/cabt" "https://dbpedia.org/sparql")
# origins
ORIGINS=("https://query.linkeddatafragments.org/" "https://yasgui.org/proxy/" "https://anydomain.org/" "https://id.cabi.org/")


#constantly reuse this sparql query statement for test
QRY="SELECT * WHERE {?s ?p ?o.} LIMIT 3"

function test_cors {
ENDPOINT=$1 # URL of endpoint
ORIGIN=$2 # URL of origin
printf "\n--\nchecking endpoint: %-50s\n from origin : %-50s...\n" "${ENDPOINT}" "${ORIGIN:-«none»}"

args=() # initialise array
args+=("-L") # follow links
#args+=("-v") # verbose output for headers
args+=("-o" "/dev/null") # ignore the actual content
args+=("-s" "-D" "-") # hide progress (silent) and dump headers

args+=("--url" "${ENDPOINT}") # the endpoint to test
args+=("--data-urlencode" "query=$QRY") # sparql query to perform
args+=("-H" "Accept: application/sparql-results+json") # conneg for type response
if [ ! -z "${ORIGIN}" ]; then # only if an origin is provided
args+=("-H" "Origin: ${ORIGIN}") # we should pass it along
fi

resp_hdrs=$(curl "${args[@]}" 2>&1 )
status=$(echo "$resp_hdrs"| head -n 1 | xargs) # xargs will strip whitespace effectively

if [[ "${status}" =~ ^HTTP.*200$ ]]; then # succesful response starts with HTTP and ends with 200
echo " +++ RESPONSE OK --> $status"
if [ -z "${ORIGIN}" ]; then
echo " and no origin to check"
else
echo " checking match origin ${ORIGIN}"
did_match_origin=$(echo "$resp_hdrs" | grep -i -P "^access-control-allow-origin: (\*|$ORIGIN)" | wc -l)
if [ "$did_match_origin" -eq "1" ]; then
echo " +++ OK, there was an origin-allow-match !"
else
echo " *** ERROR no origin-allow-match !"
fi
fi
else
echo " *** ERROR RESPONSE --> $status"
fi
}

echo "Testing CORS on combo of "
echo "endpoints ${ENDPOINTS[@]}"
echo "and origins ${ORIGINS[@]}"
echo "------------------------------"

for e in ${ENDPOINTS[@]}; do
for o in ${ORIGINS[@]}; do
test_cors $e $o
done
test_cors $e
done

echo "------------------------------"
echo "done"

Loading

0 comments on commit 985f96f

Please sign in to comment.