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:
import jnettool.tools.Routing
import jnettool.tools.elements.NetworkElement
class NetworkElementError(Exception):
pass
class NetworkElement(object):
@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 / 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 / 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 / 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_)
@brainix
brainix / analytics.coffee
Last active September 7, 2018 15:50
CoffeeScript for Google Analytics
class GoogleAnalytics
@init: (webPropertyId) ->
@_initQueue webPropertyId
scriptTag = @_createScriptTag()
@_injectScriptTag scriptTag
true
@_initQueue: (webPropertyId) ->
window._gaq ?= []
window._gaq.push ['_setAccount', webPropertyId]