Skip to content

Instantly share code, notes, and snippets.

View brainix's full-sized avatar
💻
Designed by Apple in California

Rajiv Bakulesh Shah brainix

💻
Designed by Apple in California
View GitHub Profile
@brainix
brainix / node-error.txt
Created October 28, 2021 13:07
Node.js 17.0.1 error when pushing to Heroku
rajiv.shah@C02FK16KMD6V vh1 % git push heroku master
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 16 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 4.30 KiB | 244.00 KiB/s, done.
Total 4 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
@brainix
brainix / explicit.json
Created August 6, 2021 06:02
iTunes top songs
{"feed":{"title":"Top Music Videos","id":"https://rss.itunes.apple.com/api/v1/us/music-videos/top-music-videos/all/200/explicit.json","author":{"name":"iTunes Store","uri":"http://wwww.apple.com/us/itunes/"},"links":[{"self":"https://rss.itunes.apple.com/api/v1/us/music-videos/top-music-videos/all/200/explicit.json"},{"alternate":"https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?genreId=34\u0026popId=5"}],"copyright":"Copyright © 2018 Apple Inc. Все права защищены.","country":"us","icon":"http://itunes.apple.com/favicon.ico","updated":"2021-05-25T17:11:53.000-07:00","results":[{"artistName":"BTS","id":"1568538211","releaseDate":"2021-05-21","name":"Butter","kind":"musicVideo","copyright":"℗ 2021 BIGHIT MUSIC / HYBE","artistId":"883131348","artistUrl":"https://music.apple.com/us/artist/bts/883131348","artworkUrl100":"https://is5-ssl.mzstatic.com/image/thumb/Features125/v4/10/e1/ca/10e1ca24-34f4-d46b-55c8-ad02684af94d/mza_10814629250342140759.jpg/200x200mv.png","genres":[{"genreId":"1686","name":"K-Po
@brainix
brainix / flatten.py
Last active February 9, 2021 01:52
Flatten dict tech screen
import collections
def flatten(dict_, *, separator='.', raise_on_collision=True):
flattened = {}
for key, value in dict_.items():
if isinstance(value, collections.abc.Mapping):
tmp_dict = flatten(value)
for tmp_key, tmp_value in tmp_dict.items():
tmp_key = separator.join((key, tmp_key))
@brainix
brainix / runlength.py
Last active February 7, 2021 09:22
Run-length encoding tech screen
# https://twitter.com/brainix/status/1358343863354552324
def runlength_encoding(s):
if s:
count = 1
for c1, c2 in zip(s[:-1], s[1:]):
if c1 == c2:
count += 1
else:
yield c1, count
@brainix
brainix / hanoi.py
Last active September 25, 2020 09:15
>>> def hanoi(num, from_, using, to):
... if num:
... yield from hanoi(num-1, from_, to, using)
... yield f'move disc {num} from peg {from_} to peg {to}'
... yield from hanoi(num-1, using, from_, to)
...
>>> for move in hanoi(4, 1, 2, 3):
... print(move)
...
move disc 1 from peg 1 to peg 2
@brainix
brainix / sieve.py
Last active September 25, 2020 09:19
>>> def naturals(start):
... yield start
... yield from naturals(start+1)
...
>>> def sieve(prev_sieve):
... prime = next(prev_sieve)
... yield prime
... yield from (num for num in prev_sieve if num % prime != 0)
...
>>> s = sieve(naturals(2))
@brainix
brainix / wat.py
Last active September 18, 2020 05:40
>>> j = 256
>>> k = 256
>>> j is k
True
>>> j = 257
>>> k = 257
>>> j is k
False
>>> j, k = 257, 257
>>> j is k
import random
def assertion_sort(list_):
try:
assert all(x <= y for x, y in zip(list_, list_[1:]))
except AssertionError:
random.shuffle(list_)
assertion_sort(list_)
#!/usr/bin/env python3
import sys
# Map the uppercase letters forwards:
_MAPPING = {
'Q': 'P',
'W': 'O',
@brainix
brainix / rss.xml
Created June 23, 2016 03:54
iTunes top songs
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<id>https://itunes.apple.com/us/rss/topmusicvideos/limit=200/explicit=true/xml</id><title>iTunes Store: Top Music Videos</title><updated>2016-06-22T20:09:58-07:00</updated><link rel="alternate" type="text/html" href="https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?cc=us&amp;id=1&amp;popId=5"/><link rel="self" href="https://itunes.apple.com/us/rss/topmusicvideos/limit=200/explicit=true/xml"/><icon>http://itunes.apple.com/favicon.ico</icon><author><name>iTunes Store</name><uri>http://www.apple.com/itunes/</uri></author><rights>Copyright 2008 Apple Inc.</rights>
<entry>
<updated>2016-06-22T20:09:58-07:00</updated>
<id im:id="1125405366">https://itunes.apple.com/us/music-video/this-is-what-you-came-for/id1125405366?uo=2</id>