Skip to content

Instantly share code, notes, and snippets.

@Convicted202
Convicted202 / git_branch_rename.sh
Created July 17, 2020 11:23
Git rename remote branch
# Staying on branch with name old_branch
git branch -m new_branch # Rename locally
git push origin :old_branch # Delete old branch
git push --set-upstream origin new_branch # Push, update local branch to track new remote branch
@Convicted202
Convicted202 / Instances.sh
Created April 6, 2019 12:32
Grepping instances ips from autoscaling group
1. =>
#!/bin/bash
for i in `aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name ASGName | grep -i instanceid | awk '{ print $2}' | cut -d',' -f1| sed -e 's/"//g'`
do
aws ec2 describe-instances --instance-ids $i | grep -i PrivateIpAddress | awk '{ print $2 }' | head -1 | cut -d"," -f1
done;
2. =>
aws ec2 describe-instances --region us-east-1 --instance-ids \
$(aws autoscaling describe-auto-scaling-instances --region us-east-1 --output text \
@Convicted202
Convicted202 / conv.sh
Created March 24, 2018 09:29 — forked from blairanderson/conv.sh
Optimize Videos for Web - Compress MP4 and remove Audio with FFMPEG. encodes as 264 with CRF 30, scales down to 1920x1080, strips audio
#! /bin/bash
# The Purpose of this Script is to batch convert and compress any video file to mp4 format
#
# WARNING: LOSSY COMPRESSION !!!
# Variable used:
# sourcedir is the directory where to be converted videos are. Converted video will be saved in the same folder
# usage:
@Convicted202
Convicted202 / promise-retry.js
Created February 8, 2018 11:50
Promises retry maxTries
function waitFor (time, promiseFn = () => {}) {
const wait = new Promise(resolve => {
setTimeout(resolve, time);
});
return Promise.all([promiseFn, wait]).then(
args => args[0] && typeof args[0] === 'function' && args[0](),
() => Promise.reject('Error in waitFor')
);
}
@Convicted202
Convicted202 / crypto-pbkdf2-example.js
Created April 23, 2017 20:58 — forked from skeggse/crypto-pbkdf2-example.js
Example of using crypto.pbkdf2 to hash and verify passwords asynchronously, while storing the hash and salt in a single combined buffer along with the original hash settings
var crypto = require('crypto');
// larger numbers mean better security, less
var config = {
// size of the generated hash
hashBytes: 32,
// larger salt means hashed passwords are more resistant to rainbow table, but
// you get diminishing returns pretty fast
saltBytes: 16,
// more iterations means an attacker has to take longer to brute force an
@Convicted202
Convicted202 / ImgDataPoly.js
Last active October 16, 2020 07:37
ImageData Polyfill IE11
(() => {
try {
new window.ImageData(new Uint8ClampedArray([0, 0, 0, 0]), 1, 1);
} catch (e) {
function ImageDataPolyfill () {
let args = [...arguments], data;
if (args.length < 2) {
throw new TypeError(`
Failed to construct 'ImageData': 2 arguments required, but only ${args.length} present.
@Convicted202
Convicted202 / function-web-worker.js
Created March 15, 2017 12:27 — forked from westonruter/function-web-worker.js
Spawning a web worker from a function object (bypassing need for separate JS file)
function fibonacci(){ /*...*/ }
var worker = new Worker(
"data:application/javascript;base64,"+
btoa('(' + fibonacci.toString().replace(/function\s+\w+/, 'function') + ')();')
);
// More: https://plus.google.com/113853198722136596993/posts/hAtcYGc5xcw
@Convicted202
Convicted202 / 0_reuse_code.js
Created July 28, 2016 12:51
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Convicted202
Convicted202 / main.js
Created July 19, 2016 14:12 — forked from husa/xml2react.js
XML to React Component
const xml = `
<XMLText class="yeah-attributes">
regular text
<XMLBold>
bold text
</XMLBold>
another text
</XMLText>
`;
@Convicted202
Convicted202 / Attaching localization
Last active August 29, 2015 14:10
Usefull files for MCSD
<h2><span data-win-res="{textContent: 'greeting'}"></span></h2>
and resource file with .resjson extension within strings folder:
eng
{
"greeting" : "Hello",
"_greeting.comment" : "A welcome greeting"
}