Skip to content

Instantly share code, notes, and snippets.

View inactivist's full-sized avatar
💭
fixing things

Michael Curry inactivist

💭
fixing things
View GitHub Profile
@coryhouse
coryhouse / PromptOnUnload.jsx
Last active January 7, 2022 11:53
Prompt user when they navigate away
import React, { useEffect } from "react";
import PropTypes from "prop-types";
import { Prompt } from "react-router-dom";
// Prompt the user onbeforeunload or when navigating away by clicking a link
export default function PromptOnUnload({ when, message }) {
const enabled = when;
useEffect(() => {
if (!enabled) return;
const handleBeforeUnload = (event) => {
@thenishchalraj
thenishchalraj / ReactSampleGrafanaComponent.js
Last active March 21, 2023 13:05
Dynamically embedding Grafana Dashboards and panels. (code snippet)
import React from 'react'
//configuration file that has the values stored for users
import config from './config'
class SampleDashboard extends React.Component {
render() {
//suppose user is received from props
const { user } = this.props
return (
@richard-savant
richard-savant / pytest_flask_fixtures.py
Created March 27, 2020 20:36 — forked from qodot/pytest_flask_fixtures.py
Pytest Fixtures (Flask, SQLAlchemy, Alembic)
import sys
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from alembic.command import upgrade as alembic_upgrade
from alembic.config import Config as AlembicConfig
from wsgi import create_app
from config import config
@inactivist
inactivist / luigi_first_steps.md
Last active July 13, 2023 09:12 — forked from tomsing1/luigi_first_steps.md
First steps with the Luigi workflow manager

First steps with the Luigi workflow manager

As an introduction into Luigi, I am following this tutorial with some modifications, e.g. installation using conda.

The problems and solutions described in the examples below have led to the development of sciluigi,

@screeny05
screeny05 / index.ts
Last active October 21, 2021 19:16
Native File System Typescript Typings – https://wicg.github.io/native-file-system/
declare global {
enum ChooseFileSystemEntriesType {
'open-file',
'save-file',
'open-directory'
}
interface ChooseFileSystemEntriesOptionsAccepts {
description?: string;
mimeTypes?: string;
@ld-web
ld-web / useIsMounted.js
Created December 25, 2019 11:12
useIsMounted custom React hook
import React, { useEffect } from 'react';
/**
* useIsMounted hook can be used to check if a component is still mounted.
* Then, one can prevent a state update on an unmounted component, and therefore avoid memory leaks
*/
function useIsMounted() {
const isMounted = React.useRef(true);
useEffect(() => {
@frank-dspeed
frank-dspeed / 2018-https-localhost.md
Last active February 4, 2025 17:41 — forked from cecilemuller/2019-https-localhost.md
How to create an HTTPS certificate for localhost domains

How to create an HTTPS certificate for localhost domains

This focuses on generating the certificates for loading local virtual hosts hosted on your computer, for development only.

Do not use self-signed certificates in production ! For online certificates, use Let's Encrypt instead (tutorial).

Create a own domain (1-10 Domains No Wildcards)

edit /etc/hosts add my.

@movalex
movalex / toggle_swap.sh
Last active September 6, 2022 09:18 — forked from Jekis/toggle_swap.sh
Empty swap. Clear swap. Move swap to RAM. Ubuntu.
#!/bin/bash
function calc_percentage () {
mem="$1"
total="$2"
if [[ $mem -gt 0 ]]; then
return $((mem * 100 / total))
else
return 0
fi
@jaklinger
jaklinger / es_keyword_expansion.py
Last active March 4, 2020 22:25
How to get keyword expansion using elasticsearch
import requests
import json
def make_query(url, q, alg, field, shard_size=1000, size=25):
"""Get keywords relating to the input query, directly from Elasticsearch
Args:
url (str): The Elasticsearch endpoint you want to query
q (str): The query you want to retrieve keywords for
alg (str): An algorithm from https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-significantterms-aggregation.html#_parameters

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database