Git Product home page Git Product logo

codechirps's Introduction

CodeChirps

Introducing "CodeChirps" - bite-sized code snippets for every digital nest builder out there, ready to help you soar through your coding journey! ๐Ÿฆ๐Ÿ’ป #CodeChirps #FlyWithCode

GCheck

A short script to login and check your gmail account. I was going to use this to auto reply to users responding to a "no-reply@" mailbox, only to realize, that they are also using auto responders. ๐Ÿ˜•

    // Connect to gmail
    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
    $username = file_get_contents('GmailSmtpUsername.secret');
    $password = file_get_contents('GmailSmtpPassword.secret');

    // Try to connect
    $inbox = imap_open($hostname,$username ,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

    // Grab pretty emails
    $emails = imap_search($inbox,'ALL');
    if($emails) {

        // Put the newest emails on top
        rsort($emails);

        // Loop over emails
        foreach($emails as $emailNumber) {

            // Get information on this email */
            $overview = imap_fetch_overview($inbox, $emailNumber, 0);

            // Print email information
            print $overview[0]->from . ' - ' . $overview[0]->subject . PHP_EOL;
        }
    }

    // Close the connection
    imap_close($inbox);

StreamGPT

If you want to ๐Ÿ˜Ž steam from OpenAI just like the big kids do๐Ÿš€, here is how to do it with PHP from the command line ๐Ÿ’ป. #chatGPT4 #OpenAi #php #CodeChirps ๐Ÿฆ๐Ÿค–โœจ

// To run, type: php StreamGPT.php

// Set API key and endpoint
$api_key =  file_get_contents('openAiKey.secret');
$endpoint = "https://api.openai.com/v1/chat/completions";

// Create a cURL session
$ch = curl_init($endpoint);

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "Authorization: Bearer {$api_key}"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    "model"            => 'gpt-4',
    "messages" => [
        [
            "role"    => "user",
            "content" => "You are ChatGPT, a large language model trained by OpenAI. Please answer the following question: What is the capital of South Africa?"
        ],
    ],
    "temperature"       => 1, // Control's randomness, less is more deterministic
    "top_p"             => 0, // Diversity
    "n"                 => 1, // Number of choices to return
    "frequency_penalty" => 0, // Penalize new tokens based on their existing frequency
    "presence_penalty"  => 0, // Penalize new tokens based on whether they appear in the text so far
    "stream"            => 1  // Stream back partial results as they are generated, instead of waiting for completion
]));

// The magic happens here
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {

    $string = substr($data, 6);
    if($json = json_decode($string, true)){
        if( ! empty($json['choices'][0]['delta']['content']) ) {
            print $json['choices'][0]['delta']['content'];
        }
    }

    return strlen($data); // Return the number of bytes sent
});

curl_exec($ch);

GiggleSearch

If you ever feel the need to reinvent the wheel and build your own search engine for giggles, don't sweat it! Just use Google's API and call it "GiggleSearch"! Voila! ๐Ÿ˜‚๐Ÿ” Here's how: #Googleception #RecursionFTW #buildinpublic

// Google search endpoint
$endPoint = "https://www.googleapis.com/customsearch/v1";

// Set credentials
$apiKey  = file_get_contents('googleSearchApiKey.secret'); // Obtained from https://console.developers.google.com/apis/credentials
$cx      = file_get_contents('searchEngineId.secret'); // Obtained from https://cse.google.com/cse/all

// Set parameters ( Additional parameters can be found here: https://developers.google.com/custom-search/json-api/v1/reference/cse/list)
$start   = 1; // Start index of the results
$num     = 10; // Number of results per page, max is 10
$country = 'ZA'; // Country code to search from

// Set the query to search for in google
$query = urlencode("Open AI");

// Build the final URL
$url = $endPoint."?key={$apiKey}&cx={$cx}&gl={$country}&start={$start}&num={$num}&q={$query}";

// Get the results from google
$result = json_decode(file_get_contents($url));

// Dump the result
print_r($result);

codechirps's People

Contributors

codechap avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.