Skip to content

Instantly share code, notes, and snippets.

View akash-coded's full-sized avatar
🎯
Focusing

Akash Das akash-coded

🎯
Focusing
View GitHub Profile
@akash-coded
akash-coded / try-except-finally.py
Created March 12, 2020 14:14
Try with resources, except when you can't and finally, make things work.
try:
with open('hshhj.txt', mode = 'r'):
print("File opened")
except FileNotFoundError as e:
print("Error opening file")
print(e)
finally:
print("Some operation independent of file contents")
@akash-coded
akash-coded / check-function-arguments.py
Created March 12, 2020 14:07
Sometimes, it is required to know the arguments that a function expects, their ordering, the default values and all the other goodies. This is especially useful when we don't have access to the source code where the function has been defined. Thankfu
from googlesearch import search
import inspect
print(str(inspect.signature(search)))
@akash-coded
akash-coded / web-scraping-boilerpy.md
Last active April 25, 2025 13:34
Text extraction from websites, or Web Mining, is a major area of interest in today's connected world. Extract text content from web pages with Python tools. Some of the tools mentioned here have a more focussed approach on main text extraction wherea

1. Using BoilerPy3, a native Python port of Christian Kohlschütter's Boilerpipe for automatically extracting main textual content of a webpage based on shallow text features. It gives us the page title and it's contents

!pip install boilerpy3
from boilerpy3 import extractors

extractor = extractors.CanolaExtractor()

doc = extractor.get_doc_from_url('https://www.newsrain.in/petrol-diesel-prices/Odisha')
page_title = doc.title
@akash-coded
akash-coded / misusing-boolean-literals.php
Last active February 20, 2020 15:40
Redundant Boolean literals should be removed from expressions to improve readability and remove code smells.
<?php
// Noncompliant Code Example
if ($booleanVariable == true) { /* ... */ }
if ($booleanVariable != true) { /* ... */ }
if ($booleanVariable || false) { /* ... */ }
doSomething(!false);
$booleanVariable = condition ? true : exp;
$booleanVariable = condition ? false : exp;
@akash-coded
akash-coded / mysql-indexing.md
Last active February 4, 2020 09:49
Description about different types of constraints and all the implicit and excpilict indexing behaviour in MySQL.

MySQL can create composite indexes (that is, indexes on multiple columns). An index may consist of up to 16 columns.

MySQL can use multiple-column indexes for queries that test all the columns in the index, or queries that test just the first column, the first two columns, the first three columns, and so on. If you specify the columns in the right order in the index definition, a single composite index can speed up several kinds of queries on the same table.

A multiple-column index can be considered a sorted array, the rows of which contain values that are created by concatenating the values of the indexed columns.

Suppose that a table has the following specification:

CREATE TABLE test (
 id INT NOT NULL,
--To create a database with proper character set and collation
CREATE DATABASE IF NOT EXISTS profile_maker CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
--To see the default character set and collation for a given database, use these statements:
USE db_name;
SELECT @@character_set_database, @@collation_database;
--Alternatively, to display the values without changing the default database:
SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME
FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'db_name';
@akash-coded
akash-coded / php-multidimensional-associative-array.php
Last active January 30, 2020 13:17
Manipulating multidimensional associative arrays in PHP and using composite $_FILES[] along with foreach
<?php
$letters = ['a','b','c'];
$words = [];
$words['name'] = 'Akash';
$words['skills'] = array();
$words['vocab'] = 10;
$words['temp'] = array();
foreach($letters as $letter) {
$words['skills'][] = htmlentities($letter);
@akash-coded
akash-coded / php-varargs.php
Last active January 30, 2020 13:13
How to use varargs in PHP with token(...) symbol and func_get_args()
<?php
class Test
{
public function testing(...$args)
{
$x = func_num_args();
print_r($x);
echo "</br>";
print_r($args);
@akash-coded
akash-coded / php-function-overloading.php
Last active January 30, 2020 13:13
PHP function overloading with __call()
<?php
class OverloadingTest
{
public function __call($method, $params)
{
if($method === "select")
{
$this->testing1($params[0]);
} elseif($method === "insert") {
@akash-coded
akash-coded / States and UTs in India
Created January 26, 2020 16:21
This is an array containing names of all 28 states and 8 union territories in India. You can directly use it in your code, with minor modifications as per your programming language of choice.
$states = [
'Andaman and Nicobar Islands',
'Andhra Pradesh',
'Arunachal Pradesh',
'Assam',
'Bihar',
'Chandigarh',
'Chhattisgarh',
'Dadra and Nagar Haveli and Daman and Diu',
'Goa',