Skip to content

Instantly share code, notes, and snippets.

View rishabh-ink's full-sized avatar

Rishabh rishabh-ink

View GitHub Profile
@rishabh-ink
rishabh-ink / levitation_test_pdb_session.py
Last active March 23, 2019 22:54
Of pytest and lru_cache in Python
$ tox
...
... # content snipped
...
# The test passes for the 1st parameterized run when ordinary_object='quill'
(Pdb) ordinary_object
@rishabh-ink
rishabh-ink / levitation_fixed_test.py
Last active March 23, 2019 23:27
Of pytest and lru_cache in Python
from unittest import mock
import pytest
@pytest.mark.parametrize(
'ordinary_object',
[
'quill',
'cushion',
from unittest import mock
import pytest
@pytest.mark.parametrize(
'ordinary_object',
[
'quill',
'cushion',
@rishabh-ink
rishabh-ink / levitation.py
Last active March 23, 2019 22:45
Of pytest and lru_cache in Python
from functools import lru_cache
from spells import cast_spell
@lru_cache(maxsize=2)
def levitate(target):
"""
Levitates `target` with the "Wingardium Leviosa" spell.
:param str target: Object that you would like to levitate
@rishabh-ink
rishabh-ink / ExamplePythonCLIProgram.py
Last active March 6, 2019 05:38
A boilerplate example of a Python CLI program
# -*- coding: utf-8 -*-
import argparse
import logging
import sys
def main(argv=None):
argparser = argparse.ArgumentParser(
description='A boilerplate greeting program!',
)
@rishabh-ink
rishabh-ink / perf_hooks.js
Created July 30, 2018 23:57
Libdefs for Node’s experimental (as of v10.7.x) core module, perf_hooks
// @flow
/**
* Libdefs for Node’s experimental (as of v10.7.x) core module, perf_hooks.
*
* TODO Work in progress. Add libdefs for other functions in this module.
*
* @see https://nodejs.org/api/perf_hooks.html
*/
declare module 'perf_hooks' {
@rishabh-ink
rishabh-ink / ExampleComponent.test.js
Last active February 8, 2023 02:20
Mocking and testing fetch with Jest
import { shallow } from 'enzyme';
import ExampleComponent from './ExampleComponent';
describe('ExampleComponent', () => {
it('fetches data from server when server returns a successful response', done => { // 1
const mockSuccessResponse = {};
const mockJsonPromise = Promise.resolve(mockSuccessResponse); // 2
const mockFetchPromise = Promise.resolve({ // 3
json: () => mockJsonPromise,
@rishabh-ink
rishabh-ink / ExampleComponent.js
Last active June 3, 2018 23:33
Mocking fetch in Jest
import React, { Component } from 'react';
class ExampleComponent extends Component {
componentDidMount() {
const fetchedData = this.fetchDataFromServer();
// ... do something with fetchedData e.g. set the data
}
async fetchDataFromServer() {
@rishabh-ink
rishabh-ink / dependencies.txt
Created July 15, 2017 15:40
openSUSE Leap 42.2 - Kvantum dependencies
gcc
libQt5Svg5
libqt5-qtsvg-devel
libqt5-qtx11extras-devel
libX11-devel
libQt5Widgets-devel
libQt5PlatformHeaders-devel
// ----
// Sass (v3.4.7)
// Compass (v1.0.1)
// ----
/* Alias */
$config__tile: (
"active": (
"background-color": #4C9CEA,