Skip to content

Instantly share code, notes, and snippets.

View ilyas-shah's full-sized avatar
👨‍💻
Contributing

Ilyas Shah ilyas-shah

👨‍💻
Contributing
  • Bangalore, India
View GitHub Profile
@ilyas-shah
ilyas-shah / array_sub_sequence.js
Created September 6, 2022 18:39
Find sub-sequence in an array - Javascript
function findSubsequence (arr = [], subArr = []) {
let prevIndex = 0;
for(let i = 0; i < subArr.length; i++) {
const item = subArr[i];
const index = arr.indexOf(item);
if ( index >= 0) {
if (prevIndex > index) return false;
@ilyas-shah
ilyas-shah / handle_errors.go
Created February 4, 2022 11:21
Tour of GO Error exercise
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
return fmt.Sprint("Can't Sqrt negative number: ", float64(e))
@ilyas-shah
ilyas-shah / GenerateURL.js
Created June 30, 2021 08:28
Generate URL dynamically in JS
const generateURL = (data = {}) => {
const domain = 'http://testurl.bitfinix.com';
let queryString = '';
for (const key in data) {
if (data[key])
queryString += `${key}=${data[key]}&`;
}
return `${domain}/${queryString ? '?' + queryString.slice(0, -1) : ''}`;
}
@ilyas-shah
ilyas-shah / ExampleReactWithRedux.js
Last active June 30, 2021 03:52
Example: Data fetching in React component using Redux
import React, {useEffect} from 'react';
import {connect} from 'react-redux';
// React Component
const A = props => {
useEffect(() => {
// fetch data from a remote server
props.fetchData()
}, [props]);
@ilyas-shah
ilyas-shah / round_close_btn.css
Created October 25, 2020 15:03
Close round button in CSS
.close__btn {
position: absolute;
right: -18px;
top: -18px;
border: 1px solid white;
box-shadow: -6px 1em 3em 0px rgba(0, 0, 0, 0.1);
border-radius: 25px 25px 25px 25px;
width: 40px;
text-align: center;
background: white;
@ilyas-shah
ilyas-shah / remove_all_newlines_tabs_regex.js
Created May 2, 2019 06:23
JS Remove all new lines and tabs using regex
{str}.replace(/[\t\n\r]/gm,'')
@ilyas-shah
ilyas-shah / text_to_speech.py
Last active March 23, 2019 14:30
Text to speech in Python using pyttsx3
# Install python, 3.xx recommended
# Run the following commands:
# pip install pyttsx3
# save below code in a file and name as whatever you want.
# To run this code, type "python <your filename.py>"
# the above command will prompt to write something, once you write, press Enter
# and it will say the text you wrote.
# import library into code
# know about this library at: https://pyttsx.readthedocs.io/en/latest/
@ilyas-shah
ilyas-shah / sha256.js
Created January 16, 2019 11:13
JavaScript function to encrypt a string to SHA256
function SHA256(s){
var chrsz = 8;
var hexcase = 0;
function safe_add (x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
function S (X, n) { return ( X >>> n ) | (X << (32 - n)); }
function R (X, n) { return ( X >>> n ); }
@ilyas-shah
ilyas-shah / retry.js
Created November 6, 2018 19:05
retrying a request after some timeout
function wait (timeout) {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
}, timeout)
})
}
async function requestWithRetry (url) {
const MAX_RETRIES = 10
@ilyas-shah
ilyas-shah / checkEmpty.js
Created November 7, 2017 12:00
function to check for empty objects.
function isEmpty (obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) { return false }
}
return true
}