Skip to content

Instantly share code, notes, and snippets.

from sly import Lexer, Parser
class CalcLexer(Lexer):
tokens = { TYPE_DECLARATION, SPACE, COLLAN, ASSIGN, NAME, TYPEOF, END, LPAREN, RPAREN }
ignore = ' \t'
# Tokens
NAME = r'[a-zA-Z_][a-zA-Z0-9_]*'
# NUMBER = r'\d+'
@ankur0101
ankur0101 / validation.js
Created September 23, 2021 06:03
[SAPUI5] UI Validation
debugger;
var softModel = this.getView().getModel('softModel');
var softModelData = softModel.getData();
var selectedRequestID = this.getView().byId('RequestTypeSelect').getSelectedKey();
var i18nBundle = this.getView().getModel('i18n').getResourceBundle();
switch (selectedRequestID) {
case "2":
if (softModel.getProperty("/selectedBankAccount") == "0") {
// return [false, "Please select bank account"];
return [false, i18nBundle.getText("e_type2__bank_account_select")];
@ankur0101
ankur0101 / concurrency.py
Created February 20, 2023 06:29
Python concurrency
import time
from multiprocessing import Process, Pipe
def sleeper(seconds, conn):
time.sleep(seconds)
conn.send("Got up after "+str(seconds)+" seconds")
conn.close()
print("Processed: "+str(seconds))
if __name__ == '__main__':
@ankur0101
ankur0101 / layer.sh
Created February 20, 2023 10:55
Building layers for Lambda Layers
$ pip install \
--platform manylinux2010_x86_64 \
--implementation cp \
--python 3.9 \
--only-binary=:all: --upgrade \
--target awsbundle \
cryptography
@ankur0101
ankur0101 / grecaptchav2.js
Created May 29, 2023 07:44
SAPUI5 custom control for Google reCaptcha V2
sap.ui.define([
'sap/ui/core/Control'
], function(Control, ) {
'use strict';
return Control.extend("enkompass.control.grecaptchav2", {
metadata : {
properties: {
key: {type: "string", defaultValue : 0},
size: {type: "string", defaultValue : "normal"}
}
#!/bin/bash
# Replace with your actual API Gateway ID
API_GATEWAY_ID="your-id-here"
# Header for CSV format
echo "Resource ID,Resource Path,HTTP Method,Integration,Authorizer Name,Authorizer Type"
# Step 1: Get a list of resources and paths
resources_info=$(aws apigateway get-resources --rest-api-id "$API_GATEWAY_ID" --query 'items[].{id: id, path: path}' --output json)
@ankur0101
ankur0101 / lambda2git.py
Created July 31, 2023 14:34
A python snippet to retrieve all lambda functions to store under git
import boto3
import os
import sys
import requests
from pathlib import Path
import zipfile
fn_client = boto3.client("lambda")
dir_name = 'lambda_functions'
Path("./"+str(dir_name)).mkdir(parents=True, exist_ok=True)
@ankur0101
ankur0101 / updteCORS.py
Last active September 2, 2023 07:18
AWS API Gateway resource CORS configuration updater
import boto3
# Initialize the Boto3 client for API Gateway
client = boto3.client('apigateway')
# Define the API Gateway resource ID and the new CORS settings
resource_id = 'your-resource-id'
new_cors_settings = {
"allowOrigins": ['https://example.com'],
"allowHeaders": ['Authorization', 'Content-Type'],
@ankur0101
ankur0101 / node.sh
Created November 29, 2023 07:34
Running node-cli inside Cloud Foundry Application
#!/bin/bash
./deps/0/bin/node $@
# Now ./node.sh server.js will work
@ankur0101
ankur0101 / npm.sh
Created November 29, 2023 07:35
Running npm to install package inside Cloud Foundry deployed application
#!/bin/bash
./deps/0/bin/node ./deps/0/node/bin/npm $@
# Now "./npm.sh install express" will work