Skip to content

Instantly share code, notes, and snippets.

@yuryoparin
yuryoparin / google_oauth2.sh
Created May 4, 2014 11:19
Google OAuth 2.0 in Bash
#! /bin/bash
# The approx. time to run this script is 145 ms.
# First we extract the private PEM key from the .p12 file:
# openssl pkcs12 -nocerts -passin 'notasecret' -in file.p12 -out ~/google/google.privatekey.pem
KEY='~/google/google.privatekey.pem'
# The fields are ordered by their hash values.
# In Google Client for Java HashMap is used to stack all JSON fields, so String.hashCode() is used for ordering.
@yuryoparin
yuryoparin / google_token_redis.sh
Last active August 29, 2015 14:00
Put Google OAuth 2.0 access token to Redis
#echo "access_token = $access_token" # valid for 3600 seconds
access_token=ya29.1.AADtN_XKybIzhN-3SUdWkwm2AETJWRKjaiimgTA4U2tR2yF2R42b16Ipz-03FfUI
# The while-loop waits 60 seconds for Redis to start after reboot
cnt=0
PING=$(/usr/local/bin/redis-cli PING 2>&1) # stderr to stdout
while [ "$PING" != "PONG" ] && (($cnt < 6)); do
sleep 10;
let cnt=$cnt+1
@yuryoparin
yuryoparin / youtube_v3_api_list_result
Created May 4, 2014 12:23
Youtube API v3 list result example
{
"kind": "youtube#videoListResponse",
"etag": "\"N5Eg36Gl054SUNiWWc-Su3t5O-k/znsgxR5z9807wYDi_7GxzUgNXOc\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
@yuryoparin
yuryoparin / base64url-wrong.sh
Last active August 29, 2015 14:01
Base64url encoding broken
#! /bin/bash
table=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 - _ =)
#text="{\"alg\":\"RS256\",\"typ\":\"JWT\"}"
#text="{\"iss\":\"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com\",\"scope\":\"https://www.googleapis.com/auth/prediction\",\"aud\":\"https://accounts.google.com/o/oauth2/token\",\"exp\":1328554385,\"iat\":1328550785}"
read text
# breaking binary represantation of $text in to 6-bit blocks
@yuryoparin
yuryoparin / base64url.sh
Last active July 29, 2020 07:19
Base64url encoding
#! /bin/bash
table=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 - _ =)
#text="{\"alg\":\"RS256\",\"typ\":\"JWT\"}"
#text="{\"iss\":\"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com\",\"scope\":\"https://www.googleapis.com/auth/prediction\",\"aud\":\"https://accounts.google.com/o/oauth2/token\",\"exp\":1328554385,\"iat\":1328550785}"
read text
# breaking binary represantation of $text in to 6-bit blocks
@yuryoparin
yuryoparin / epochta-sms-api-v3-getAddressbook.sh
Last active March 25, 2017 08:03
Получение списка адресных книг в ePochta SMS API v3 через bash однострочник
#!/bin/bash
key='Публичный ключ';
pr_key='Приватный ключ';
action='getAddressbook'; echo -e "key=$key;version=3.0;action=$action" | \
tr ';' '\n' | \
sort -t'=' -k1 | \
cut -f2 -d'=' | \
paste -s -d';' - | \
@yuryoparin
yuryoparin / epochta-sms-api-v3.sh
Last active March 25, 2017 08:02
Общее описание запроса в ePochta SMS API v3 через bash однострочник
#!/bin/bash
key='Публичный ключ';
pr_key='Приватный ключ';
action='Команда'; echo -e "key=$key;version=3.0;action=$action;param1=val1;...;paramN=valN" | \
tr ';' '\n' | \
sort -t'=' -k1 | \
cut -f2 -d'=' | \
paste -s -d';' - | \
@yuryoparin
yuryoparin / epochta-sms-api-v3-getAllAddressBookVariables.sh
Last active March 25, 2017 08:02
Список переменных в адресной книге для ePochta SMS API v3 через bash однострочник
#!/bin/bash
key='Публичный ключ';
pr_key='Приватный ключ';
action='getAllAddressBookVariables'; echo -e "key=$key;version=3.0;action=$action;idAddressBook=853365" | \
tr ';' '\n' | \
sort -t'=' -k1 | \
cut -f2 -d'=' | \
paste -s -d';' - | \
@yuryoparin
yuryoparin / epochta-sms-api-v3-checkCampaignPrice.sh
Last active March 25, 2017 08:01
Запрос цены смс рассылки для адресной книги в ePochta SMS API v3 через bash однострочник
#!/bin/bash
key='Публичный ключ';
pr_key='Приватный ключ';
action='checkCampaignPrice'; printf '%s;' "key=$key" 'version=3.0' "action=$action" 'sender=COMPANY' 'text=%Name% %NameMiddle%! Перед началом весеннего сезона хотим предложить новую машинку со скидкой по цене 3999 руб. Подробнее https://goo.gl/%URL% и тел. 84950000000' 'list_id=853365' 'type=2' | \
sed 's/;$//' | tr ';' '\n' | \
sort -t'=' -k1 | \
cut -f2 -d'=' | \
paste -s -d';' - | \
@yuryoparin
yuryoparin / epochta-sms-api-v3-createCampaign.sh
Last active March 25, 2017 08:01
Отправка смс рассылки для адресной книги в ePochta SMS API v3 через bash однострочник
#!/bin/bash
key='Публичный ключ';
pr_key='Приватный ключ';
action='createCampaign'; printf '%s;' "key=$key" 'version=3.0' "action=$action" 'sender=COMPANY' 'text=%Name% %NameMiddle%! Перед началом весеннего сезона хотим предложить новую машинку со скидкой по цене 3999 руб. Подробнее https://goo.gl/%URL% и тел. 84950000000' 'list_id=853365' 'type=2' | \
sed 's/;$//' | tr ';' '\n' | \
sort -t'=' -k1 | \
cut -f2 -d'=' | \
paste -s -d';' - | \