Skip to content

Instantly share code, notes, and snippets.

View FonzTech's full-sized avatar
😄
Developing

Alfonso FonzTech

😄
Developing
View GitHub Profile
@janzikan
janzikan / resize_image.php
Last active May 13, 2024 09:05
PHP: Resize image - preserve ratio of width and height
/**
* Resize image - preserve ratio of width and height.
* @param string $sourceImage path to source JPEG image
* @param string $targetImage path to final JPEG image file
* @param int $maxWidth maximum width of final image (value 0 - width is optional)
* @param int $maxHeight maximum height of final image (value 0 - height is optional)
* @param int $quality quality of final image (0-100)
* @return bool
*/
function resizeImage($sourceImage, $targetImage, $maxWidth, $maxHeight, $quality = 80)
@andelf
andelf / sendMail.go
Last active September 20, 2023 15:13
golang send mail net/smtp SMTP
package main
import (
"log"
"net/mail"
"encoding/base64"
"net/smtp"
"fmt"
"strings"
@krusynth
krusynth / simpleXML_to_object.php
Created September 6, 2013 13:33
Translates a simpleXML object into a standard PHP object.
<?php
/*
* Translate a non-standard object into an associative array object.
* Super-useful for dealing with simplexml objects.
*/
function simpleXML_to_object($obj)
{
$data = new StdClass();
if(
(is_object($obj) && get_class($obj) == 'SimpleXMLElement')
@sergiotapia
sergiotapia / md5-example.go
Last active December 5, 2023 03:53
Golang - How to hash a string using MD5.
import (
"crypto/md5"
"encoding/hex"
)
func GetMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
@turret-io
turret-io / aes_enc_dec.php
Last active June 5, 2024 21:34
AES encryption/decryption in PHP
<?php
// DEFINE our cipher
define('AES_256_CBC', 'aes-256-cbc');
// Generate a 256-bit encryption key
// This should be stored somewhere instead of recreating it each time
$encryption_key = openssl_random_pseudo_bytes(32);
// Generate an initialization vector
// This *MUST* be available for decryption as well
@castorflex
castorflex / ASCIIFolding.java
Last active February 24, 2023 21:49
Java ASCII Folding
public class ASCIIFolding {
@NonNull
public static String foldToASCII(@NonNull String input) {
return foldToASCII(input, new StringBuilder(input.length()));
}
@NonNull
public static String foldToASCII(@NonNull String input, @NonNull StringBuilder sb) {
final int end = input.length();
@jim3ma
jim3ma / starttls_smtp_example.go
Last active July 1, 2024 00:01 — forked from chrisgillis/ssl_smtp_example.go
Golang StartTLS SMTP Example
package main
import (
"fmt"
"log"
"net"
"net/mail"
"net/smtp"
"crypto/tls"
)
@dixudx
dixudx / StreamToString.go
Created November 16, 2016 09:34 — forked from tejainece/StreamToString.go
Golang: io.Reader stream to string or byte slice
import "bytes"
func StreamToByte(stream io.Reader) []byte {
buf := new(bytes.Buffer)
buf.ReadFrom(stream)
return buf.Bytes()
}
func StreamToString(stream io.Reader) string {
buf := new(bytes.Buffer)
@nikhita
nikhita / update-golang.md
Last active July 19, 2024 17:55
How to update the Go version

How to update the Go version

System: Debian/Ubuntu/Fedora. Might work for others as well.

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

@dyerrington
dyerrington / overfitting_decision_trees.md
Created May 12, 2017 19:10
Re: Why are decision trees prone to overfitting, I’ll do my best --

Overfitting in decision trees

Overfitting can be one problem that describes if your model no longer generalizes well.

Overfitting happens when any learning processing overly optimizes training set error at the cost test error. While it’s possible for training and testing to perform equality well in cross validation, it could be as the result of the data being very close in characteristics, which may not be a huge problem. In the case of decision tree’s they can learn a training set to a point of high granularity that makes them easily overfit. Allowing a decision tree to split to a granular degree, is the behavior of this model that makes it prone to learning every point extremely well — to the point of perfect classification — ie: overfitting.

I recommend the following steps to avoid overfitting:

  • Use a test set that is not exactly like the training set, or different enough that error rates are going to be easy to see.