Skip to content

Instantly share code, notes, and snippets.

View imvaskii's full-sized avatar
🎯
Focusing

Bhaskar imvaskii

🎯
Focusing
View GitHub Profile
@imvaskii
imvaskii / match_p_tags.php
Created November 19, 2018 00:01
Match all HTML p tags
<?php
function match_all_p_tags( $str ) {
$re = '/<p.+>*[\w\s]*<\/p>/m';
$p_tags_count = preg_match_all( $re, $str, $matches, PREG_SET_ORDER, 0 );
var_dump( $p_tags_count, $matches )
}
@imvaskii
imvaskii / codedeploy-github.sh
Last active November 20, 2018 00:05
AWS cli CodeDeploy github commit
#!/usr/bin/env bash
# If arg numbers ($#) is 0 display usage message.
[[ $# -eq 0 || -z $1 || -z $2 || -z $3 ]] && {
# <repo-name> string string Org name followed by repo name e.g. google/coding-with-chrome
printf 'Usage: %s <application-name> <deployment-group> <repo-name> <commit-id>
<application-name> string CodeDeploy Application name
<deployment-group> string CodeDeploy Development Group name
<commit-id> string git commit SHA1
@imvaskii
imvaskii / boto3-s3_move_object.py
Created October 11, 2018 03:06
Moves s3 file from one location to another.
def move_s3_key(source, destination_key, destination_bucket=None):
"""Moves s3 key from source bucket to destination bucket
Arguments:
source {dict} -- A dictionary containing 'Bucket' and 'Key'
destination_key {str} -- Destination key
Keyword Arguments:
destination_bucket {str} -- Desitnation bucket (default: {None})
@imvaskii
imvaskii / read-iptc.py
Created October 4, 2018 13:34
Read IPTC info from a image file in python #python #iptc
# pip install pillow
from PIL import Image, IptcImagePlugin
im = Image.open('/home/bhaskark/Pictures/iptc-test.jpg')
iptc = IptcImagePlugin.getiptcinfo(im)
if iptc:
for k, v in iptc.items():
print("{} {}".format(k, repr(v.decode())))
@imvaskii
imvaskii / restart_n_wait.sh
Created October 3, 2018 05:06
Restart and wait 10 secs
# ready services required by codedeploy
# restart codedeploy-agent and nginx server
function restart_svc_n_wait() {
gem install net-telnet -v 0.1.1
puppet agent -tv
/etc/init.d/codedeploy-agent restart
/etc/init.d/nginx restart
# time to ready service to available
sleep 5
}
@imvaskii
imvaskii / article-health-check.sh
Created October 3, 2018 00:08
Curl request to healthcheck web url
# Does health check of an article
# curl request to the TEST_URL
#
# Returns the exit code
function article_health_check() {
response=$(curl -sL -w "%{http_code}" ${TEST_URL} -o /dev/null)
if [ $response -eq 200 ]; then
return 0
else
return 1
@imvaskii
imvaskii / wait-and-retry.sh
Created October 2, 2018 09:31
A bash function to wait and retry command.
# Public: Execute commands until 5 consecutive time waiting 15 seconds in each retries.
#
# Takes a single argument.
#
# $@ - Passed argument to be executed.
#
# Examples
#
# retry rake spec
@imvaskii
imvaskii / author-date-fixer.sh
Created August 1, 2018 10:52
git commit author/date amend
#!/usr/bin/env bash
# http://stackoverflow.com/questions/821396/aborting-a-shell-script-if-any-command-returns-a-non-zero-value
set -e
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "1 argument required, $# provided"
@imvaskii
imvaskii / interface
Last active July 24, 2018 11:33
/etc/network/interfaces - raspi defalut network interface
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
@imvaskii
imvaskii / attachment-id-cap.php
Last active June 25, 2018 06:27
Regex to capture attachment ID from image tag markup.
<?php
/**
* Returns attachment ids from the string using regex.
* match string "wp-image-{the-id-here}"
* regex101 link: https://regex101.com/r/aacOaV/1/
*
* @param string $content
* @return array array of attachment ids.
*/
public function get_attachment_ids_from_content( $content ) {