lunes, 27 de noviembre de 2023

Count Textarea Characters with JavaScript


I've been playing around with the Twitter API lately and, as you know, Tweets can only be 140 characters long. I wanted to use a textarea element, not an input type="text", so I couldn't just use maxchars to limit the number of characters. Additionally, I get annoyed when my text is chopped off when pasting. So, what to do? Well, I thought, why not make a little character counter like the one you find on the actual Twitter?

The first step is to create the JavaScript function. I placed mine in a file called count-chars.js and it looks like this:

function countChars(textbox, counter, max) {
  var count = max - document.getElementById(textbox).value.length;
  if (count < 0) { document.getElementById(counter).innerHTML = "<span style=\"color: red;\">" + count + "</span>"; }
  else { document.getElementById(counter).innerHTML = count; }
}

textbox and counter are the IDs of the elements of the textarea we're counting and the span where the count is going to go, respectively.

There's lots you can customize there. You could disable the form if too many characters are entered or you could automatically truncate the text. But, I prefer to just have the warning show up in red text.

The next step is to write the HTML itself:

<script type="text/javascript" src="/js/count-chars.js"></script>
<form action="#" method="POST">
<p>Tweet Something: <span id="char_count"></span><br><textarea name="tweet" id="textbox" class="form-control" rows="3" cols="60" onFocus="countChars('textbox','char_count',140)" onKeyDown="countChars('textbox','char_count',140)" onKeyUp="countChars('textbox','char_count',140)"></textarea></p>
<p><input type="submit" class="btn btn-primary" value="Tweet" /></p>
</form>

domingo, 15 de octubre de 2023

GPT PDF

 https://nanonets.com/blog/chat-with-pdfs-using-chatgpt-and-openai-gpt-api/

lunes, 9 de octubre de 2023

Google tts audio generation


https://cloud.google.com/text-to-speech/docs/audio-profiles


 To generate an audio file, make a POST request and provide the appropriate request body. The following shows an example of a POST request using curl. The example uses the access token for a service account set up for the project using the Google Cloud Platform Cloud SDK. For instructions on installing the Cloud SDK, setting up a project with a service account, and obtaining an access token, see the Quickstarts.



The following example shows how to send a request to the text:synthesize endpoint.

curl \
 
-H "Authorization: Bearer "$(gcloud auth print-access-token) \
 
-H "Content-Type: application/json; charset=utf-8" \
 
--data "{
    'input':{
      'text':'This is a sentence that helps test how audio profiles can change the way Cloud Text-to-Speech sounds.'
    },
    'voice':{
      'languageCode':'en-us',
    },
    'audioConfig':{
      'audioEncoding':'LINEAR16',
      'effectsProfileId': ['telephony-class-application']
    }
  }"
"https://texttospeech.googleapis.com/v1beta1/text:synthesize" > audio-profile.txt

If the request is successful, the Text-to-Speech API returns the synthesized audio as base64-encoded data contained in the JSON output. The JSON output in the audio-profiles.txt file looks like the following:

{
 
"audioContent": "//NExAASCCIIAAhEAGAAEMW4kAYPnwwIKw/BBTpwTvB+IAxIfghUfW.."
}

To decode the results from the Cloud Text-to-Speech API as an MP3 audio file, run the following command from the same directory as the audio-profiles.txt file.

sed 's|audioContent| |' < audio-profile.txt > tmp-output.txt && \
tr -d '\n ":{}' < tmp-output.txt > tmp-output-2.txt && \
base64 tmp-output-2.txt --decode > audio-profile.wav && \
rm tmp-output*.txt

miércoles, 27 de septiembre de 2023

PDF search and sort

pdfgrep -P '\(809|829|849\)\d{7}' VILLA-NAZARET-BAYONA.pdf  | grep -oP '\((809|829|849)\).{10}'


pdfgrep -P '\(809|829|849\)\d{7}' VILLA-NAZARET-BAYONA.pdf | grep -oP '\((809|829|849)\).{10}' | sed 's/[^0-9]//g'






pdfgrep -P '\(809|829|849\)\d{7}' PRM_HATO NUEVO.pdf | grep -oP '\((809|829|849)\).{10}' | sed 's/[^0-9]//g' >  PRM _ MANOGUAYABO.txt

miércoles, 9 de agosto de 2023

domingo, 25 de junio de 2023

find if a word or substring exist based on php array

 <?php



$acctname = array(

    "Nash_paid",

    "Nash_Orange",

    "Sagi_Orange",

    "Sagu_paid",

    "Red_Phone",

    "Main_Paid",

    "Abi_Orange",

    "Abi_paid",

    "Repeated client_",

    "Meni_Road",

    "Meni_Towing",

    "Main_line");



$string="Red_Phone";

foreach($acctname as $substring){

if (stripos($string, $substring) !== false) {


echo  "$substring<br>";

}

}


?>

get the the monday and sunday from a week a go

 <?php

// Get the current date

$currentDate = date('Y-m-d');


// Calculate the previous week's Monday

$previousMonday = date('Y-m-d', strtotime($currentDate . ' -1 week monday'));


// Calculate the previous week's Sunday

$previousSunday = date('Y-m-d', strtotime($currentDate . ' -1 week sunday'));


// Display the results

echo "Previous Week's Monday: " . $previousMonday . "<br>";

echo "Previous Week's Sunday: " . $previousSunday . "<br>";

?>