Skip to content

Instantly share code, notes, and snippets.

View sanchitrk's full-sized avatar
😎
Building

Sanchit Rk sanchitrk

😎
Building
View GitHub Profile
@sanchitrk
sanchitrk / node-install.sh
Created February 22, 2023 11:02
Node Install - Ubuntu 20.04 LTS
cd ~
curl -sL https://deb.nodesource.com/setup_18.x -o /tmp/nodesource_setup.sh
sudo bash /tmp/nodesource_setup.sh
sudo apt-get install gcc g++ make
sudo apt install nodejs
@sanchitrk
sanchitrk / google-oauth.js
Created July 31, 2021 19:36 — forked from jhackett1/google-oauth.js
Using Google oAuth to authenticate a React app and Express API
////////////
// REACT APP
////////////
// Your login screen
<GoogleLogin
clientId={process.env.REACT_APP_GOOGLE_CLIENT_ID}
buttonText="Sign in with Google"
className="ct-button ct-button--secondary"
import React from 'react';
import PropTypes from 'prop-types'
import debounce from 'lodash.debounce' // or whatevs
import isEqual from 'lodash.isEqual'
class AutoSave extends React.Component {
static contextTypes = {
formik: PropTypes.object
}
import random
import time
import numpy
from exceptions import ValueError
class PushID(object):
# Modeled after base64 web-safe chars, but ordered by ASCII.
PUSH_CHARS = ('-0123456789'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@sanchitrk
sanchitrk / generate-pushid.js
Created May 11, 2020 11:12 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
from datetime import timedelta
from flask import Flask, make_response, request, current_app
from functools import update_wrapper
def crossdomain(origin=None, methods=None, headers=None, max_age=21600, attach_to_all=True, automatic_options=True):
if methods is not None:
methods = ', '.join(sorted(x.upper() for x in methods))
if headers is not None and not isinstance(headers, basestring):
headers = ', '.join(x.upper() for x in headers)
@sanchitrk
sanchitrk / __init__.py
Created June 18, 2019 04:55 — forked from theorm/__init__.py
Pluggable API using Flask MethodView.
# -*- coding: utf-8 -*-
from .bananas import Bananas
from .base import the_api
the_api.add_url_rule('/bananas', view_func=Bananas.as_view('bananas'))
the_api.add_url_rule('/farm/<farm_id>/bananas', view_func=Bananas.as_view('bananas_from_a_farm'))
__all__ = [

Keybase proof

I hereby claim:

  • I am sanchitrk on github.
  • I am sanchitrk (https://keybase.io/sanchitrk) on keybase.
  • I have a public key ASAtoIxULg5bKhlgnJ8NrVc6BKN2jXQfwIvKJbdVqHDToQo

To claim this, I am signing this object:

@sanchitrk
sanchitrk / counter_test.py
Created December 4, 2018 08:06 — forked from dpifke/counter_test.py
Performance comparison of defaultdict vs. Counter and tuple vs. namedtuple in Python
#!/usr/bin/python
#
# Copyright (c) 2012 Dave Pifke.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@sanchitrk
sanchitrk / pyls.py
Created October 2, 2018 06:59
ls unix command implementation in python
#!/usr/bin/env python
import sys, stat, os
import grp, pwd
import locale
import time
from prettytable import PrettyTable
colors={ "default":"",
"white": "\x1b[01;37m",
"gray": "\x1b[00;37m",