Skip to content

Instantly share code, notes, and snippets.

View tsertkov's full-sized avatar
🖐️
Say Hello

Aleks Tsertkov tsertkov

🖐️
Say Hello
View GitHub Profile
@tsertkov
tsertkov / create-redirects.sh
Last active December 11, 2017 08:37
AWS S3 redirect objects batch job
#!/usr/bin/env bash
bucket=redirect.example.com
target_url=https://www.example.com
create_redirect(){
aws s3api put-object \
--acl public-read \
--bucket "$bucket" \
--website-redirect-location "$2" \
@tsertkov
tsertkov / nginx-reverse-proxy-fallback.conf
Created October 6, 2017 08:08
Nginx reverse proxy with fallback and custom 404
location @custom-404 {
types { }
default_type text/html;
return 404 "404 Not Found";
}
location @reverse-proxy-fallback {
recursive_error_pages on;
proxy_intercept_errors on;
error_page 404 = @custom-404;
@tsertkov
tsertkov / download-flv-as-mp4.sh
Last active January 9, 2017 16:45
Download flv file from remote source and save it as mp4
ffmpeg -i http://www.example.com/movie.flv -c -copyts movie.mp4
@tsertkov
tsertkov / show_cert_by_fqdn.sh
Last active May 13, 2016 14:18
Display SSL certificate details by given domain name
#!/usr/bin/env bash
FQDN="$1"
[ -z "$FQDN" ] && echo "Usage: `basename $0` <fqdn>" && exit 1
echo -n \
| openssl s_client -connect "${FQDN}:443" \
| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' \
| openssl x509 -text -noout
@tsertkov
tsertkov / sed-remove-lines.sh
Created April 11, 2016 12:54
Sed remove pattern matching lines from files
sed -i.bak '/REGEXP/d' *
@tsertkov
tsertkov / getRandomArrayItems.js
Created March 10, 2015 20:39
Get given amount of random items from JavaScript array
/**
* Pick given number of random items from array
* @param {Array} array
* @param {Number} [count=1]
* @return {(*|Array)} random item or array of random items if count > 1
*/
function getRandomArrayItems(array, count) {
var
length = array.length,
randomIndexes = [],
@tsertkov
tsertkov / Code.js
Created February 17, 2015 15:39
Google Apps Script save fileBlob splitting it by chunks of given size
/**
* Save file splitting it by chunks of 9M
* @param {Blob} FileBlob blob data to save
* @param {Folder} folder destination folder
* @param {Number} chunkSize
* @return {String}
*/
function saveFileByChunks(fileBlob, folder, chunkSize) {
var
fileName = new Date().getTime(),
@tsertkov
tsertkov / index.html
Created February 6, 2015 09:32
Upload file splitting it by chunks on client side.
<div class="row"> <div class="large-12 column"> <p>Chunk Size: 1mb (1048576 bytes)</p> <input type="number" min="1048576" value="1048576" id="numChunks" /> <input type="file" id="afile" /> <div id="done"></div> <div id="bars"></div> </div> </div>
@tsertkov
tsertkov / merge.sh
Created February 6, 2015 01:17
Merge files by group pattern in current directogy
#/usr/bin/env bash
# Merge splitted files in current folder
files=$(ls | grep \\-chunk- | sed s/-chunk-.\*$// | uniq)
for file in $files; do
cat $file-chunk-* > $file && rm -f $file-chunk-*
done
@tsertkov
tsertkov / cloud-config
Last active May 28, 2021 05:18 — forked from kacinskas/CoreOS swap
cloud-config file for enabling swap on CoreOS
#cloud-config
coreos:
units:
- name: systemd-sysctl.service
command: restart
- name: create-swap.service
command: start
runtime: true
content: |