Skip to content

Instantly share code, notes, and snippets.

View Twista's full-sized avatar
😺
:q!

Michal Haták Twista

😺
:q!
View GitHub Profile
'use strict';
/**
* Follow these steps to configure the webhook in Slack:
*
* 1. Navigate to https://<your-team-domain>.slack.com/services/new
*
* 2. Search for and select "Incoming WebHooks".
*
* 3. Choose the default channel where messages will be sent and click "Add Incoming WebHooks Integration".
function download_csv(csv, filename) {
var csvFile;
var downloadLink;
// CSV FILE
csvFile = new Blob([csv], {type: "text/csv"});
// Download link
downloadLink = document.createElement("a");
@Twista
Twista / tj.py
Created October 7, 2019 12:48
TJ - parse and process large GeoJSON files with low memory overhead
"""
Utility for dealing with large (Geo) JSON files.
It provides fast and low-memory way how to process large files (tested on 1GB files, but will work for larger ones
Usage:
```python
import json
from tj import stream
from collections import namedtuple
from random import choice
from flask import Flask, jsonify
Quote = namedtuple("Quote", ("text", "author"))
quotes = [
Quote("Talk is cheap. Show me the code.", "Linus Torvalds"),
Quote("Programs must be written for people to read, and only incidentally for machines to execute.", "Harold Abelson"),
@Twista
Twista / s3.py
Created September 6, 2018 19:04
python s3 client w/ transfer acceleration support
from typing import Union, ByteString, IO, Text
import boto3
from botocore.config import Config
from botocore.exceptions import ClientError
from botocore.response import StreamingBody
class S3Exception(Exception):
pass
@Twista
Twista / fake-backend-interceptor.ts
Last active June 26, 2018 20:32
Angular Interceptors #3
import { Inject, Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';
import { API_ENDPOINT } from 'app/shared/backend/backend.config';
import { Observable, of as observableOf } from 'rxjs';
import { environment } from 'environments/environment';
@Injectable()
export class FakeBackendInterceptor implements HttpInterceptor {
// development helper for a "usually" redundant requests
@Twista
Twista / index.ts
Created June 26, 2018 20:29
Angular Interceptors #2
import { environment } from 'environments/environment';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { LogEveryRequestInterceptor } from 'app/core/dev/logeveryrequestinterceptor';
import { NgModule } from '@angular/core';
import { AppRootComponent } from 'app/core/app-root.component';
export const providers: any[] = environment.production
? []
: [{ provide: HTTP_INTERCEPTORS, useClass: LogEveryRequestInterceptor, multi: true }];
@Twista
Twista / LogEveryRequestInterceptor.ts
Last active June 26, 2018 20:28
Angular Interceptors #1
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class LogEveryRequestInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log(request);
@Twista
Twista / berlin_clock.py
Last active June 21, 2017 23:56
BerlinClock
def time(time_string: str) -> list:
try:
[hour, minute, second] = _parse_time(time_string)
except ValueError:
raise AttributeError("Invalid Input, please use hh:mm:ss")
if not _is_valid_input(hour, minute, second):
raise AttributeError("Invalid Input, not in range")
return [
@Twista
Twista / dojo.md
Last active February 15, 2017 15:08
  1. Naimplementujte tridu pro spravu rezervaci, ktera bude mit metodu available - ta bude prijmat pole "existujicich" rezervaci (intervalu) a interval, ktery bychom chteli rezervovat.

Metoda vraci boolean: True pokud je interval dostupny, jinak False.

napriklad:

class Reservations:
	def available(reservations: list, interval: tuple) -> bool:
 pass