Skip to content

Instantly share code, notes, and snippets.

View polyrand's full-sized avatar

Ricardo Ander-Egg polyrand

View GitHub Profile
@polyrand
polyrand / react_usestate_dict.js
Created October 16, 2019 16:56
Using hooks to set and update dicts as state in a react function.
import React, { useState } from "react";
import ReactDOM from "react-dom";
class ClassExample extends React.Component {
constructor(props) {
super(props);
this.state = { count: 0 };
}

Keybase proof

I hereby claim:

  • I am polyrand on github.
  • I am rickaa (https://keybase.io/rickaa) on keybase.
  • I have a public key ASBq-GgVhlonNCLCA_47BxcZvf7c36TH5w_J-C6zt_qj9Ao

To claim this, I am signing this object:

@polyrand
polyrand / useEffect.js
Last active January 26, 2020 20:51
useEffect snippet
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
// import "./App.css";
class ExampleClass extends React.Component {
constructor(props) {
super(props);
this.state = { count: 0 };
}
@polyrand
polyrand / useState.js
Created January 26, 2020 20:52
useState snippet
import React, { useState } from "react";
import ReactDOM from "react-dom";
// import "./App.css";
class ClassExample extends React.Component {
constructor(props) {
super(props);
this.state = { count: 0 };
}
Non-user install because user site-packages disabled
Created temporary directory: /private/var/folders/gz/zzx2nwnj45x024zrqbkr0cm00000gn/T/pip-ephem-wheel-cache-6n511flg
Created temporary directory: /private/var/folders/gz/zzx2nwnj45x024zrqbkr0cm00000gn/T/pip-req-tracker-rb5j0ih0
Initialized build tracking at /private/var/folders/gz/zzx2nwnj45x024zrqbkr0cm00000gn/T/pip-req-tracker-rb5j0ih0
Created build tracker: /private/var/folders/gz/zzx2nwnj45x024zrqbkr0cm00000gn/T/pip-req-tracker-rb5j0ih0
Entered build tracker: /private/var/folders/gz/zzx2nwnj45x024zrqbkr0cm00000gn/T/pip-req-tracker-rb5j0ih0
Created temporary directory: /private/var/folders/gz/zzx2nwnj45x024zrqbkr0cm00000gn/T/pip-install-xiyr_889
1 location(s) to search for versions of gensim:
* https://pypi.org/simple/gensim/
Fetching project page and analyzing links: https://pypi.org/simple/gensim/
@polyrand
polyrand / repr_list.py
Last active July 5, 2020 14:15
Representing simple lists in Python. Useful for teaching.
from typing import Iterable
def get_repr(elem, l):
if len(str(elem)) > l:
return str(elem)[: l - 3] + "..."
return str(elem)
@polyrand
polyrand / reorder_data.py
Last active May 25, 2020 07:57
TFG snippet
new_cols_nodrug = [c for c in df.columns.to_list() if c not in all_drug_cols]
new_cols = new_cols_nodrug.copy()
for i in range(len(drugs)):
new_cols.append(f"drug_{i}")
new_cols.append(f"pasi_inicial_{i}")
new_cols.append(f"tiempo_{i}")
new_cols.append(f"motivo_{i}")
-- walkthrough of: https://mystery.knightlab.com
--
/* A crime has taken place and the detective needs
* your help. The detective gave you the crime
* scene report, but you somehow lost it. You
* vaguely remember that the crime was a murder
* that occurred sometime on Jan.15, 2018 and that
* it took place in SQL City. Start by retrieving
* the corresponding crime scene report from the
* police department’s database. */
@polyrand
polyrand / docdec.py
Created July 27, 2020 20:48
Write python docstrings in a separate text file.
# docd.py
def doc(f):
with open("docs.txt") as d:
docfile = d.read()
# save old docstring
if f.__doc__:
prev_doc = f.__doc__
f.__doc__ = prev_doc + "\n\n# docdoc\n" + docfile
@polyrand
polyrand / parse_sql_return.py
Last active March 7, 2024 20:56
Decorator to parse the results of a raw sqlalchemy query to a Pydantic model.
import inspect
from functools import partial, wraps
from typing import Union
from app import schemas
from app.db import database
from pydantic.main import ModelMetaclass
from shortuuid import uuid
# The following 2 functions parse raw results from the SQL queries