Skip to content

Instantly share code, notes, and snippets.

View snasirca's full-sized avatar

Shahriyar Nasir snasirca

View GitHub Profile
@snasirca
snasirca / refactor-prototype-js-to-jquery.sh
Last active September 24, 2021 19:28
Refactor from PrototypeJS to jQuery
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
#for filename in $(find ./modules -type f); do
for filename in $(rg -l --pcre2 --type "js" --type "erb" --type "ruby" '(?<!\.)\$?\$F?\(['"'"'"]?(\w|#{)' --glob '!vendor' --glob '!infrastructure' --glob '!docker' --glob '!modules/generic/legacy_javascript/app/assets/javascripts/jquery'); do
perl -p -i -e "s/(?<!\\$)\\$\(this\).show\(\)/jQuery(this).show()/g" "${filename}"
perl -p -i -e "s/(?<!\\$)\\$\('(\w[^\(\)]*)'\).show\(\)/jQuery('#\$1').show()/g" "${filename}"
perl -p -i -e "s/(?<!\\$)\\$\(\"(\w[^\(\)]*)\"\).show\(\)/jQuery(\"#\$1\").show()/g" "${filename}"
@snasirca
snasirca / get-json.js
Created February 10, 2019 20:47
Function for getting JSON data from endpoints using only built-in Node libraries
const { URL } = require('url')
const getJson = (url, options = {}) => new Promise((resolve, reject) => {
const urlParsed = new URL(url)
const lib = urlParsed.protocol === 'http' ? require('http') : require('https')
let optionsWithUrl = {
path: urlParsed.pathname + urlParsed.search,
host: urlParsed.hostname,
...options
}
@snasirca
snasirca / put_s3.sh
Last active May 1, 2017 02:35 — forked from chrismdp/s3.sh
Uploading to S3 using just Bash
#!/usr/bin/env bash
# Originally copied from: https://gist.github.com/chrismdp/6c6b6c825b07f680e710
# Required Environment Variables:
# - AWS_ACCESS_KEY_ID
# - AWS_SECRET_ACCESS_KEY
if [ $# -ne 3 ]; then
echo "Usage: put_s3.sh DIRECTORY_TO_PUT S3_BUCKET S3_DIRECTORY_PATH"
# ----------------------------------------------------------------------------------------------------------------
# Elasticsearch-Toronto Meetup: Zero Downtime (part 1 of 3)
# ----------------------------------------------------------------------------------------------------------------
# My presentation at the second elasticsearch meetup in Toronto
# April 21, 2015
# http://www.meetup.com/ElasticSearch-toronto
# http://www.meetup.com/Elasticsearch-Toronto/events/220384588/
# ----------------------------------------------------------------------------------------------------------------
# Demo with elasticsearch 1.5.1 and Marvel/Sense
# Installation: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_installing_elasticsearch.html

Keybase proof

I hereby claim:

  • I am snasirca on github.
  • I am snasirca (https://keybase.io/snasirca) on keybase.
  • I have a public key whose fingerprint is 79B0 46B3 8B40 A4B4 9D45 4D14 87E7 89F0 6AB2 0A42

To claim this, I am signing this object:

# ----------------------------------------------------------------------------------------------------------------
# Elasticsearch-Toronto Meetup: The Power of Mapping (part 1 of 3)
# ----------------------------------------------------------------------------------------------------------------
# My presentation at the first elasticsearch meetup in Toronto
# January 19, 2015
# http://www.meetup.com/ElasticSearch-toronto
# http://www.meetup.com/Elasticsearch-Toronto/events/218903340
# ----------------------------------------------------------------------------------------------------------------
# Demo with elasticsearch 1.4.2 and Marvel/Sense
# Installation: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_installing_elasticsearch.html
# ----------------------------------------------------------------------------------------------------------------
# Elasticsearch-Toronto Meetup: The Power of Mapping (part 1 of 3)
# ----------------------------------------------------------------------------------------------------------------
# My presentation at the first elasticsearch meetup in Toronto
# January 19, 2015
# http://www.meetup.com/ElasticSearch-toronto
# http://www.meetup.com/Elasticsearch-Toronto/events/218903340
# ----------------------------------------------------------------------------------------------------------------
# Demo with elasticsearch 1.4.2 and Marvel/Sense
# Installation: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_installing_elasticsearch.html