Skip to content

Instantly share code, notes, and snippets.

View shenoy-anurag's full-sized avatar
🎯
Focusing

Anurag shenoy-anurag

🎯
Focusing
View GitHub Profile
/******************************************************************************
* MSP430G2553 ACLK Test
*
* Description: This code can be used to test if you have installed the
* 32.768kHz crystal on your LaunchPad correctly. Using this code
* LED1 (on P1.0) will turn on for 1 second, and off for one
* second. You can verify this with either an oscilloscope, logic
* analyzer, or by inspection. Simple as that!
*
* This code was originally created for "NJC's MSP430
@shenoy-anurag
shenoy-anurag / resize_and_pad_image_to_square.py
Created September 14, 2018 07:11
This script will resize to an intermediate size and pad an image to desired square size while keeping its aspect ratio unchanged.
import cv2
import numpy as np
def intermediate_scaling(img, intermediate_size):
(rows, cols) = img.shape
image_size = max(rows, cols)
# Rescale to intermediate_size pixels so that image size resembles average size of dataset item.
# For example a sample character is resized to average size of dataset
scaling_factor = intermediate_size / image_size
def find(key, dictionary):
for k, v in dictionary.iteritems():
if k == key:
yield v
elif isinstance(v, dict):
for result in find(key, v):
yield result
elif isinstance(v, list):
for d in v:
for result in find(key, d):
@shenoy-anurag
shenoy-anurag / mongodb_schema_validation_creator_basic.py
Created December 23, 2019 12:52
Python script to generate Basic MongoDB Schema Validation. Doesn't support enums and other datatypes yet.
import json
import datetime
from bson import ObjectId
def get_mongodb_type(data_type):
if data_type is None:
return 'null'
elif type(data_type) == type(""):
return "string"
@shenoy-anurag
shenoy-anurag / python_naming_conventions.md
Last active January 28, 2020 12:58
Python Naming Conventions

Python Naming Conventions:

Classes:

  • Case: PascalCase
  • Keep it short and descriptive. Preferably a noun e.g. Car, Bird, MountainBike. Avoid acronyms and abbreviations.
  • Eg: OrderNumberGenerator() or Order()

Instance Variables:

  • Case: snake_case/lower_with_under
  • eg: self.items_list = []
[2020-07-31 15:39:10,659: INFO/MainProcess] Connected to amqp://guest:**@rabbitmq:5672//
[2020-07-31 15:39:10,659: DEBUG/MainProcess] ^-- substep ok
[2020-07-31 15:39:10,659: DEBUG/MainProcess] | Consumer: Starting Events
[2020-07-31 15:39:10,660: DEBUG/MainProcess] Closed channel #1
[2020-07-31 15:39:10,677: DEBUG/MainProcess] Start from server, version: 0.9, properties: {'capabilities': {'publisher_confirms': True, 'exchange_exchange_bindings': True, 'basic.nack': True, 'consumer_cancel_notify': True, 'connection.blocked': True, 'consumer_priorities': True, 'authentication_failure_close': True, 'per_consumer_qos': True, 'direct_reply_to': True}, 'cluster_name': 'rabbit@rabbitmq', 'copyright': 'Copyright (c) 2007-2020 VMware, Inc. or its affiliates.', 'information': 'Licensed under the MPL 1.1. Website: https://rabbitmq.com', 'platform': 'Erlang/OTP 23.0.3', 'product': 'RabbitMQ', 'version': '3.8.5'}, mechanisms: [b'PLAIN', b'AMQPLAIN'], locales: ['en_US']
[2020-07-31 15:39:10,680: DEBUG/MainProcess] ^-- sub
amqp.exceptions.RecoverableConnectionError: Socket was disconnected
[2020-07-31 15:46:57,623: WARNING/MainProcess] > /usr/local/lib/python3.6/dist-packages/celery/worker/consumer/consumer.py(332)start()
-> self.on_close()
[2020-07-31 15:46:57,624: WARNING/MainProcess] (Pdb)
nn
[2020-07-31 15:47:13,396: WARNING/MainProcess] ***
[2020-07-31 15:47:13,397: WARNING/MainProcess] NameError: name 'nn' is not defined
[2020-07-31 15:47:13,397: WARNING/MainProcess] (Pdb)
n
[2020-07-31 15:47:16,017: WARNING/MainProcess] > /usr/local/lib/python3.6/dist-packages/celery/worker/consumer/consumer.py(333)start()
@shenoy-anurag
shenoy-anurag / celery-connreset_once.txt
Created August 4, 2020 16:26
Celery conn resets once and thus repeats long task once. `BROKER_HEARTBEAT = 600` is the setting that causes this to happen.
[2020-08-04 16:14:17,553: INFO/MainProcess] Received task: long_running_task[b9a90217-05ed-4eb7-9bcd-d3e3fb9c4ed0]
[2020-08-04 16:14:17,554: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x7f5bf3fe8378> (args:('long_running_task', 'b9a90217-05ed-4eb7-9bcd-d3e3fb9c4ed0', {'lang': 'py', 'task': 'long_running_task', 'id': 'b9a90217-05ed-4eb7-9bcd-d3e3fb9c4ed0', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'b9a90217-05ed-4eb7-9bcd-d3e3fb9c4ed0', 'parent_id': None, 'argsrepr': '()', 'kwargsrepr': "{'n': 150}", 'origin': 'gen6@ae9258ba9c7c', 'reply_to': '357fb0b0-5899-39c6-9d44-cf757030071a', 'correlation_id': 'b9a90217-05ed-4eb7-9bcd-d3e3fb9c4ed0', 'hostname': 'celery@eddee4e4fd64', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': False}, 'args': [], 'kwargs': {'n': 150}}, '[[], {"n": 150}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]', 'application/json', 'utf-8'
@shenoy-anurag
shenoy-anurag / LinkedStack.py
Created August 8, 2020 23:16
An implementation of stacks using a linked list
class Node:
def __init__(self, item, next):
self.item = item
self.next = next
class LinkedStack:
def __init__(self):
self.n = 0
self.first = None
@shenoy-anurag
shenoy-anurag / run_jupyter.py
Created October 23, 2020 23:20
Run Jupyter notebook
import subprocess
# Run Jupyter notebook server:
subprocess.call(["jupyter", "notebook"])
# Install Kernel:
# subprocess.call(['ipython', 'kernel', 'install', '--user', '--name=venv'])