Skip to content

Instantly share code, notes, and snippets.

View hygull's full-sized avatar
😃
Enjoying work at AIPALETTE & in home. Programming is there as my best friend.

Rishikesh Agrawani hygull

😃
Enjoying work at AIPALETTE & in home. Programming is there as my best friend.
View GitHub Profile
@hygull
hygull / Conversion of a simple Month Year string to short form.md
Last active March 22, 2020 18:27
Conversion of a simple Month Year string to short form

An Illustration

> function getDateShortName(s, shortYear=true) {
...     let parts = s.split(/\s+/ig)
...     
...     if(shortYear) {
.....         return parts[0].slice(0, 3) + '\'' + parts[1].slice(2)
.....     } else {
..... return parts[0].slice(0, 3) + '\'' + parts[1]
@hygull
hygull / regex-list-dict-based-python-q-for-beginners.md
Last active November 23, 2019 05:30
Regex list dict based Python question for beginners
@hygull
hygull / pattern-based-python-q-for-beginners.md
Last active November 23, 2019 04:09
Pattern based Python question for beginners

Cab Service Based Project Doc

Objective

  • To book vehicle to visit places near by Bangalore.

    • People can book vehicles without any registration by using their mobile numbers.
  • In first page, they can enter place details as follows:

Just to understand where exactly you have to do the modification and what little mistake you did has already been pointed out in the above comments.

> var arr = [ "{\"id\": \"amzn\", \"price\": 1785.6600341796875, \"_attachments\": \"attachments/\"}", "{\"id\": \"msft\", \"price\": 138.42999267578125, \"_attachments\": \"attachments/\"}", "{\"id\": \"googl\", \"price\": 1244.280029296875, \"_attachments\": \"attachments/\"}", "{\"id\": \"ba\", \"price\": 331.05999755859375, \"_attachments\": \"attachments/\"}", "{\"id\": \"air.pa\", \"price\": 122, \"_attachments\": \"attachments/\"}" ]
undefined
> 
> item0 = arr[0]
'{"id": "amzn", "price": 1785.6600341796875, "_attachments": "attachments/"}'
> 
> item0Obj = JSON.parse(item0)
{ id: 'amzn', price: 1785.6600341796875, _attachments: 'attachments/' }
@hygull
hygull / setattr-stkovrflw.md
Last active September 23, 2019 17:09
Use of setattr() function to set attributes of class object

setattr()

Check my answer at https://stackoverflow.com/a/58067032/6615163

>>> class TEST:
...     def __init__(self, project = 'ABC', scenarios = {'A': [1,2,3], 'B': [4,5,6]}):
...         self.project = project
... for feature in scenarios:
>>> import requests
>>> 
>>> res = requests.get("https://www.amazon.in/b/ref=s9_acsd_hfnv_hd_bw_b3iMERj_ct_x_ct00_w?_encoding=UTF8&node=10485223031&pf_rd_m=A1VBAL9TL5WCBF&pf_rd_s=merchandised-search-3&pf_rd_r=59M3EPGWMDMASM4XWYPJ&pf_rd_r=59M3EPGWMDMASM4XWYPJ&pf_rd_t=101&pf_rd_p=e2e13b35-daa5-587b-aab3-6e9e9135fd3c&pf_rd_p=e2e13b35-daa5-587b-aab3-6e9e9135fd3c&pf_rd_i=3403856031")
>>> 
>>> res.status_code
200
>>> 
>>> res.text
@hygull
hygull / Solution-to-a list-dict-base-problem.md
Last active June 28, 2019 23:41
Solution to a list dict base problem, https://stackoverflow.com/questions/56814001/updating-json-fields-with-values-from-list (Unfortunately, the guy deleted the post)

Problem

In Python, list, dictionary are reference types. So if you will append the same dictionary to a list and if you will make any change to any of the dictionary, it will reflect in all other as well because all are pointing to the same memory location.

>>> l = [{"name": "Raghavendra Thakur", "age": 27}] * 4
>>> 
>>> l
[{'name': 'Raghavendra Thakur', 'age': 27}, {'name': 'Raghavendra Thakur', 'age': 27}, {'name': 'Raghavendra Thakur', 'age': 27}, {'name': 'Raghavendra Thakur', 'age': 27}]
>>> 
>>> l[0]
@hygull
hygull / roserocket-entity-fields.md
Last active June 22, 2019 05:12
Roserocket get fields for ORDER, COMMODITY, CUSTOMER

Get entity fields - Roserocket (Customer, Order, Commodity)

// --- Date: 20 June 2019 ---
function get_customer_fields() {
    let customer_fields = [
        "address_1",
        "address_2",
        "billing_contact_email",
        "billing_contact_name",
@hygull
hygull / Python script to find the first repeated character in string.py
Last active May 29, 2019 01:33
Python script to find the first repeated character in string created by hygull - https://repl.it/HJ0l/0
"""
{
"created_on" : "14 April 2017",
"aim_of_script" : "Python script to find the first repeated character in string",
"coded_by" : "Rishikesh Agrawani",
"python_version" : "2.7.12",
"special" : "As an alternative to the pyscript available at http://www.geeksforgeeks.org/find-the-first-repeated-character-in-a-string/?utm_source=feedburner&utm_medium=email&utm_campaign=Feed%3A+Geeksforgeeks+%28GeeksforGeeks%29"
}
"""