Here is an example of the KMP algorithm implemented in Python:
def KMPSearch(pat, txt):
M = len(pat)
N = len(txt)
# create lps[] that will hold the longest prefix suffix
# values for pattern
lps = [0]*M
j = 0 # index for pat[]
# Preprocess the pattern (calculate lps[] array)
computeLPSArray(pat, M, lps)
i = 0 # index for txt[]
while i < N:
if pat[j] == txt:
i += 1
j += 1
if j == M:
print("Found pattern at index " + str(i-j))
j = lps[j-1]
# mismatch after j matches
elif i < N and pat[j] != txt:
# Do not match lps[0..lps[j-1]] characters,
# they will match anyway
if j != 0:
j = lps[j-1]
else:
i += 1
def computeLPSArray(pat, M, lps):
len = 0 # length of the previous longest prefix suffix
lps[0] = 0 # lps[0] is always 0
i = 1
# the loop calculates lps for i = 1 to M-1
while i < M:
if pat == pat[len]:
len += 1
lps = len
i += 1
else:
if len != 0:
len = lps[len-1]
# Also, note that we do not increment i here
else:
lps = 0
i += 1
txt = "ABABDABACDABABCABAB"
pat = "ABABCABAB"
KMPSearch(pat, txt)
This code creates two functions: KMPSearch and computeLPSArray. The KMPSearch function takes in a pattern and a text string as arguments and searches for occurrences of the pattern within the text string. The computeLPSArray function takes in a pattern, its length, and an array to hold the longest prefix suffix values for the pattern. It preprocesses the pattern to calculate the values in the array.
The thought of the last paragraph made me laughThis AI is dangerous. If misinformation is a problem now, it will be nothing compared to computerised comments posted everywhere, pushing an agenda, propaganda.
You can be sure that governments, political parties and dictators will misuse this technology for their own benefit. We might see regulations come in eventually over its use, but it won't be enough.
Just imagine having a heated argument with a troll in an article comment section only for that to be AI, but hiding that fact. And that's only the start.
How would Meghan have felt being sold off like a slave?I wonder how the AI feels about being profiteered off?
I'm joking now, but if such an AI ever becomes sentient, then it may well have something to say about this.
I can relate to this FFSI keep thinking of Skynet every time I read the above posts about AI
I get paywalls and login to read this article but also find them annoying. I know what they are doing and why, but what annoys me is some websites take information from other websites, put a twist of their own on the article and paywall it. I've found that I can take the same title of the website that's pay-walled their article, and find the same information on another website that's free.
Here’s an example of how you can use the WordPress REST API to retrieve all posts and save them to an SQL database:
import requests
import json
import pymysql
# Connect to the database
connection = pymysql.connect(host='localhost',
user='your_username',
password='your_password',
db='your_database_name')
# Create a cursor object
cursor = connection.cursor()
# Set the URL for the WordPress REST API endpoint
url = 'https://yourwordpresssite.com/wp-json/wp/v2/posts'
# Make a GET request to the WordPress REST API
response = requests.get(url)
# Load the response data as a JSON object
data = json.loads(response.text)
# Loop through each post in the data
for post in data:
# Get the post ID, title, and content
post_id = post['id']
post_title = post['title']['rendered']
post_content = post['content']['rendered']
# Create an INSERT statement to insert the post into the database
sql = "INSERT INTO your_table_name (post_id, post_title, post_content) VALUES (%s, %s, %s)"
# Execute the INSERT statement
cursor.execute(sql, (post_id, post_title, post_content))
# Commit the changes to the database
connection.commit()
# Close the database connection
connection.close()
This code uses Python’s requests library to make a GET request to the WordPress REST API and retrieve all posts. The posts are then saved to an SQL database using Python’s pymysql library. You’ll need to replace your_username, your_password, your_database_name, yourwordpresssite.com, and your_table_name with your own values.
Sure! Here’s an example of how you can create a bar chart using React and Nivo.rocks:
import React from 'react';
import { ResponsiveBar } from '@nivo/bar';
const data = [
{
"country": "AD",
"hot dog": 134,
"hot dogColor": "hsl(183, 70%, 50%)",
"burger": 12,
"burgerColor": "hsl(183, 70%, 50%)",
"sandwich": 190,
"sandwichColor": "hsl(183, 70%, 50%)",
"kebab": 184,
"kebabColor": "hsl(183, 70%, 50%)",
"fries": 16,
"friesColor": "hsl(183, 70%, 50%)",
"donut": 68,
"donutColor": "hsl(183, 70%, 50%)"
},
];
const MyResponsiveBar = () => (
<ResponsiveBar
data={data}
keys={[ 'hot dog', 'burger', 'sandwich', 'kebab', 'fries', 'donut' ]}
indexBy="country"
margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
padding={0.3}
valueScale={{ type: 'linear' }}
indexScale={{ type: 'band', round: true }}
colors={{ scheme: 'nivo' }}
borderColor={{ from: 'color', modifiers: [ [ 'darker', 1.6 ] ] }}
axisTop={null}
axisRight={null}
axisBottom={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: 'country',
legendPosition: 'middle',
legendOffset: 32
}}
axisLeft={{
tickSize: 5,
tickPadding: 5,
tickRotation: 0,
legend: 'food',
legendPosition: 'middle',
legendOffset: -40
}}
labelSkipWidth={12}
labelSkipHeight={12}
labelTextColor={{ from: 'color', modifiers: [ [ 'darker', 1.6 ] ] }}
legends={[
{
dataFrom: 'keys',
anchor: 'bottom-right',
direction: 'column',
justify: false,
translateX:120,
translateY:-10,
itemsSpacing:-10,
itemWidth:-10,
itemHeight:-10,
itemDirection:'left-to-right',
itemOpacity:-10,
symbolSize:-10,
effects:[
{
on:'hover',
style:{
itemOpacity:-10
}
}
]
}
]}
animate={true}
motionStiffness={90}
motionDamping={15}
/>
)
This code creates a bar chart using the ResponsiveBar component from the @nivo/bar package. The data for the chart is defined in the data variable and passed to the data prop of the ResponsiveBar component. You can customize the appearance and behavior of the chart by adjusting the props passed to the ResponsiveBar component.
I hope this helps! Let me know if you have any questions or need further assistance.
Name a human who is genuinely honest on planet Earth.People deserve to be paid for their work, indeed....my point was when large websites copy original work and paywall it as if the news is exclusive to them (eg. the website copies the work without acknowledgement to the original author), that's where I get annoyed...I think that's dishonest. I wasn't too clear.
Cute on the ChatGBT for Nerdzone!
Oh come on FFS that’s just regurgitating the documentation !What I find most impressive about ChatGPT for coding is that it is familiar with a number of third-party libaries.
Two example code responses from ChatCPT, one with the popular Wordpress API and the second with a less-known library for visualization called Nivo.rocks:
But within seconds and with great comments (sometimes).Oh come on FFS that’s just regurgitating the documentation !
Yeah I know I posted but within seconds and with great commentsBut within seconds and with great comments.
The speed is impressive, sure, but with web scraping, web crawlers, search engines and all that that’s to be expectedBut within seconds and with great comments.
Here’s an example of how you can get the 10 most recent threads from XenForo using the XenForo API:
<?php
// Set your API key and forum URL
$apiKey = 'YOUR_API_KEY';
$forumUrl = 'https://yourforum.com';
// Create a function to make requests to the XenForo API
function xf_request($method, $endpoint, $data = array()) {
global $apiKey, $forumUrl;
// Set the request URL
$url = $forumUrl . '/api/' . $endpoint;
// Set the request headers
$headers = array(
'XF-Api-Key: ' . $apiKey,
'Content-Type: application/json'
);
// Initialize cURL
$ch = curl_init();
// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the request method and data
if ($method == 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
} else if ($method == 'GET' && !empty($data)) {
curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($data));
}
// Execute the cURL request
$response = curl_exec($ch);
// Close cURL
curl_close($ch);
// Decode the response and return it
return json_decode($response);
}
// Get the 10 most recent threads using the XenForo API
$threads = xf_request('GET', 'threads', array('limit' => 10));
// Print the threads
print_r($threads);
This code is similar to the previous example but adds an additional parameter to the xf_request function call to specify that only 10 threads should be returned. This is done by passing an array with a limit key set to 10 as the third argument to the xf_request function.
The response from the API will contain only the 10 most recent threads. These are decoded from JSON and printed.
Yeah the concern my boss had was “what if it’s inaccurate? ChatGPT is relatively new so perhaps with time that view will change. But there ‘s always a chance that AI could be wrong and that could F things up.”To me, it's a similar situation with students writing a term paper. ChatGPT will help get the ball rolling and with providing information/education. For coding, this may help free one's mind from trivial details to more design concerns.
It may also help novice and mid-level developers to understand new frameworks, reducing "cognitive load."
It is familiar with the Xenforo forum API as well:
OpenAI Platform
Explore developer resources, tutorials, API docs, and dynamic examples to get the most out of OpenAI's platform.platform.openai.com
The AI Text Classifier is a fine-tuned GPT model that predicts how likely it is that a piece of text was generated by AI from a variety of sources, such as ChatGPT.
This classifier is available as a free tool to spark discussions on AI literacy. For more information on ChatGPT's capabilities, limitations, and considerations in educational settings, please visit our documentation.
We use essential cookies to make this site work, and optional cookies to enhance your experience.