Skip to content

Instantly share code, notes, and snippets.

Avatar
🐶
Exiting Vim!!!

Sanskar Jethi sansyrox

🐶
Exiting Vim!!!
View GitHub Profile
View Fix python unsupported locale error in Debian based distro
I was installing some python libraries that I needed, and this message came up:
Traceback (most recent call last):
File "/usr/bin/pip3", line 11, in <module>
sys.exit(main())
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 215, in main
locale.setlocale(locale.LC_ALL, '')
File "/usr/lib/python3.5/locale.py", line 594, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
@sansyrox
sansyrox / flask-aiohttp.md
Last active Sep 1, 2020
Async requests in Flask
View flask-aiohttp.md

Since flask doesn't support async coroutines it is not trivial to create aiohttp routes

There are 2 ways to create and work with these routines

aio Event loop

import asyncio
from flask import Flask

async def abar(a):
    print(a)
@sansyrox
sansyrox / nginxproxy.md
Created Aug 29, 2020 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?
View nginxproxy.md

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@sansyrox
sansyrox / sort.py
Created Jul 1, 2020
Custom Comparator sort in python
View sort.py
from functools import cmp_to_key
sorted(mylist, key=cmp_to_key(compare))
def compare(item1, item2):
if fitness(item1) < fitness(item2):
return -1
elif fitness(item1) > fitness(item2):
return 1
else:
return 0
@sansyrox
sansyrox / heap.py
Created Jul 1, 2020
Custom Comparators in Python heap
View heap.py
class FreqWord(object):
def __init__(self, freq, word):
self.freq = freq
self.word = word
def __lt__(self, other):
if self.freq != other.freq:
return lt(self.freq, other.freq)
else:
# opposite sort
@sansyrox
sansyrox / FB-PE-InterviewTips.md
Created May 18, 2020 — forked from ameenkhan07/FB-PE-InterviewTips.md
Facebook Production Engineering Interview
View FB-PE-InterviewTips.md

What to Expect and Tips

• 45-minute systems interview, focus on responding to real world problems with an unhealthy service, such as a web server or database. The interview will start off at a high level troubleshooting a likely scenario, dig deeper to find the cause and some possible solutions for it. The goal is to probe your knowledge of systems at scale and under load, so keep in mind the challenges of the Facebook environment.
• Focus on things such as tooling, memory management and unix process lifecycle.

Systems

More specifically, linux troubleshooting and debugging. Understanding things like memory, io, cpu, shell, memory etc. would be pretty helpful. Knowing how to actually write a unix shell would also be a good idea. What tools might you use to debug something? On another note, this interview will likely push your boundaries of what you know (and how to implement it).

Design/Architecture 

Interview is all about taking an ambiguous question of how you might build a system and letting

@sansyrox
sansyrox / Contract Killer 3.md
Created May 13, 2020 — forked from malarkey/Contract Killer 3.md
The latest version of my ‘killer contract’ for web designers and developers
View Contract Killer 3.md

Contract Killer

The popular open-source contract for web professionals by Stuff & Nonsense

  • Originally published: 23rd December 2008
  • Revised date: March 15th 2016
  • Original post

@sansyrox
sansyrox / postgres-brew.md
Created Apr 17, 2020 — forked from ibraheem4/postgres-brew.md
Installing Postgres via Brew (OSX)
View postgres-brew.md

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@sansyrox
sansyrox / parse_json.py
Created Mar 17, 2020 — forked from amaciel81/parse_json.py
Import a JSON file. If condition is met, print two attributes.
View parse_json.py
from json import load as json_load
with open("sample_input.json") as input_fh:
people = json_load(input_fh)
for person in people["people"]:
if person["age"] >= 30:
print("Name: {name}, City: {city}".format(name=person["name"], city=person["city"]))
@sansyrox
sansyrox / parse_csv.py
Created Mar 17, 2020 — forked from amaciel81/parse_csv.py
Import a CSV file. If condition is met, print two attributes for that condition
View parse_csv.py
from csv import reader as csv_reader
with open("sample_input.csv") as input_fh:
people = csv_reader(input_fh)
headers = next(people)
for row in people:
person = (dict(zip(headers, row)))
if int(person["age"]) >= 30:
print("Name: {name}, City: {city}".format(name=person["name"], city=person["city"]))
You can’t perform that action at this time.