Skip to content

Instantly share code, notes, and snippets.

View CaselIT's full-sized avatar

Federico Caselli CaselIT

View GitHub Profile
@CaselIT
CaselIT / CustomExceptionHandler.ts
Last active August 4, 2016 15:34
Angular custom exception handler
/**
* Custom logger that saves the logging.
* The console logging logic if from BrowserDomAdapter
* https://github.com/angular/angular/blob/master/modules/@angular/platform-browser/src/browser/browser_adapter.ts#L69
*/
class CustomLogger {
errorLog: any[] = [];
logError(error: any) {
this.errorLog.push(error);
if (window.console.error) {
@CaselIT
CaselIT / mozlz4a.py
Created November 27, 2017 20:31 — forked from Tblue/mozlz4a.py
MozLz4a compression/decompression utility
#!/usr/bin/env python
#
# Decompressor/compressor for files in Mozilla's "mozLz4" format. Firefox uses this file format to
# compress e. g. bookmark backups (*.jsonlz4).
#
# This file format is in fact just plain LZ4 data with a custom header (magic number [8 bytes] and
# uncompressed file size [4 bytes, little endian]).
#
# This Python 3 script requires the LZ4 bindings for Python, see: https://pypi.python.org/pypi/lz4
#
@CaselIT
CaselIT / errors.txt
Created January 26, 2020 10:10
Falcon 3 dev errors on windows
server_port = testing.get_unused_port()
base_url = 'http://{}:{}/'.format(_SERVER_HOST, server_port)
with _run_server_isolated(process_factory, _SERVER_HOST, server_port) as server:
# NOTE(kgriffs): Let the server start up. Give up after 5 seconds.
start_ts = time.time()
while (time.time() - start_ts) < 5:
try:
requests.get(base_url, timeout=0.2)
@CaselIT
CaselIT / main.py
Created April 3, 2020 20:24 — forked from henribru/main.py
`selectinload` doesn't load all relationships when used with `with_polymorphic` and subclasses have relationships with the same name
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey, inspect
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, with_polymorphic, selectinload
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///:memory:', echo=True)
Session = sessionmaker(bind=engine)
Base = declarative_base()
@CaselIT
CaselIT / make_data.py
Created December 18, 2023 18:19
Create random dataframe with specified number of partitions of random size
# License: MIT
from argparse import ArgumentParser
from itertools import product
import numpy as np
import pandas as pd
_r = 8750
_c = 15
_sizes = {