Skip to content

Instantly share code, notes, and snippets.

View adityathebe's full-sized avatar
🏠
Working from home

Aditya Thebe adityathebe

🏠
Working from home
View GitHub Profile
@trenskow
trenskow / toCase.js
Last active July 18, 2022 11:02
An convenience method for converting to and from different casing types.
if (!String.prototype.toCase) {
Object.defineProperties(String.prototype, {
'toCase': {
value: function(type = 'camel') {
const seperators = {
'camel': '',
'pascal': '',
'snake': '_',
'domain': '.',
@tylerburdsall
tylerburdsall / asynchronous_example.py
Last active December 23, 2022 19:34
Example showing asynchronous HTTP request with Python 3.5.0 + asyncio
import requests
import asyncio
from concurrent.futures import ThreadPoolExecutor
from timeit import default_timer
START_TIME = default_timer()
def fetch(session, csv):
base_url = "https://people.sc.fsu.edu/~jburkardt/data/csv/"
with session.get(base_url + csv) as response:
@adityathebe
adityathebe / pixelmapper.js
Last active March 26, 2018 04:43
A function to map rgba value into better accessible pixels
/*
* A function to map rgba value into better accessible pixels
* */
// ========= Actual Pixels ( 2x2 image ) ==========
/*
let x = [
[1, 2],
[3, 4]
]
@soulmachine
soulmachine / jwt-expiration.md
Last active June 21, 2024 14:09
How to deal with JWT expiration?

First of all, please note that token expiration and revoking are two different things.

  1. Expiration only happens for web apps, not for native mobile apps, because native apps never expire.
  2. Revoking only happens when (1) uses click the logout button on the website or native Apps;(2) users reset their passwords; (3) users revoke their tokens explicitly in the administration panel.

1. How to hadle JWT expiration

A JWT token that never expires is dangerous if the token is stolen then someone can always access the user's data.

Quoted from JWT RFC:

@onjin
onjin / docker-compose.yml
Created September 5, 2016 09:17
example docker compose for postgresql with db init script
postgres:
image: postgres:9.4
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
@hugohil
hugohil / server.py
Created June 28, 2016 12:55
Basic python 2.7 REST API
#!/usr/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
PORT_NUMBER = 8080
PUBLIC_ENTRY = './public/index.html'
# This class will handles any incoming request
class handleRoutes(BaseHTTPRequestHandler):
# Handler for the GET requests
def do_GET(self):
@saggiyogesh
saggiyogesh / mongo_dump_restore.md
Last active December 3, 2020 18:26
Mongodb dump and restore from mlab
  • install mongodb on local machine (mongodump & mongorestore) commands are required.
  • command dumping

mongodump -h xxx11.mlab.com:11 -u user -p password --authenticationDatabase release-db -d release-db -o /home/dumps

**Options** `-h`: mlab host:port, `-u`: db user, `-p`: db user password, `--authenticationDatabase` `-d`: mlab dbname, `-o`: path to store backupfiles
  • restore command, to restore locally

    mongorestore --db dname /home/dumps

Otherwise to restore in mlab, create a new db and replace the options

@Jguer
Jguer / cycle_audio_output.sh
Created January 17, 2016 03:08
Cycles pulse audio output devices
#! /bin/bash
#################################################################################
# File Name : cycle_audio_output.sh
# Created By : jguer
# Creation Date : [2016-01-16 22:55]
# Last Modified : [2016-01-17 00:42]
# Description : Cycles audio output devices
#################################################################################
VERBOSITY=0
NOTIFICATIONS=0
@DmitrySoshnikov
DmitrySoshnikov / Recursive-descent-backtracking.js
Last active January 3, 2024 17:15
Recursive descent parser with simple backtracking
/**
* = Recursive descent parser =
*
* MIT Style License
* By Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*
* In this short lecture we'll cover the basic (non-predictive, backtracking)
* recursive descent parsing algorithm.
*
* Recursive descent is an LL parser: scan from left to right, doing
@branneman
branneman / better-nodejs-require-paths.md
Last active June 29, 2024 16:00
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions