Skip to content

Instantly share code, notes, and snippets.

View slav123's full-sized avatar

Slawomir Jasinski slav123

View GitHub Profile
@slav123
slav123 / post.php
Last active May 20, 2023 20:21
PHP CURL POST query multipart/form-data
<?php
curl_setopt_array($curl, array(
CURLOPT_URL => "API_ENDPOINT",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
@slav123
slav123 / restore.sh
Created March 31, 2023 08:38
Restore Files from Glacier on Amazon S3 Storage using Bash Script
#!/bin/bash
# Set your AWS region and S3 bucket name
REGION=eu-central-1
BUCKET=bucket-name
# List all objects in the bucket and change the storage class to Standard
aws s3api list-objects --region "$REGION" --bucket "$BUCKET" --query "Contents[?StorageClass=='GLACIER'].[Key]" --output text | while read -r line; do
# Skip directories
if [[ "$line" == */ ]]; then
@slav123
slav123 / unlock.sh
Created September 1, 2022 11:35
SeLinux write
#SELinux is blocking the read/write operations
chcon -Rv --type=httpd_sys_rw_content_t /var/www/html/ (if you want to allow full web root)
chcon -Rv --type=httpd_sys_rw_content_t /var/www/html/uploads/ (Or just uploads folder)
@slav123
slav123 / signed.go
Last active August 29, 2022 07:43
AWS Signed request in GO
package main
import (
"compress/gzip"
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
@slav123
slav123 / timeout.go
Created July 31, 2022 09:14
example of using timeout in go with context package
package main
import (
"context"
"fmt"
"time"
)
var globalResult []int
@slav123
slav123 / post.go
Created July 5, 2022 13:46
Send multipart/form-data form with GO
type field struct {
Key string `json:"key"`
Value string `json:"value"`
}
func Post(url string, fields []field) error {
var b bytes.Buffer
w := multipart.NewWriter(&b)
@slav123
slav123 / server.go
Created May 29, 2015 01:25
golang channels examples with tcp server
package main
import (
"io"
"log"
"net"
"bytes"
"bufio"
"strings"
"time"
@slav123
slav123 / post.go
Created June 30, 2022 06:34
golang post query with host header oberri
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
@slav123
slav123 / main.go
Created June 23, 2022 14:16
PUT presigned url example in Go
// main.go
package main
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
@slav123
slav123 / gist:3616736
Created September 4, 2012 04:55
RTF to plaintext
<?php
// Function that checks whether the data are the on-screen text.
// It works in the following way:
// an array arrfailAt stores the control words for the current state of the stack, which show that
// input data are something else than plain text.
// For example, there may be a description of font or color palette etc.
function rtf_isPlainText($s) {
$arrfailAt = array("*", "fonttbl", "colortbl", "datastore", "themedata");
for ($i = 0; $i < count($arrfailAt); $i++)