Skip to content

Instantly share code, notes, and snippets.

View piotrgrundas's full-sized avatar
:octocat:

Piotr Grundas piotrgrundas

:octocat:
View GitHub Profile
@piotrgrundas
piotrgrundas / EventEmitter.ts
Last active November 14, 2023 12:29
pub-sub EventEmitter
type EventCallback<Opts extends unknown = any> = Opts extends undefined
? (opts?: undefined) => void
: (opts: Opts) => void;
class EventEmitter<EventType = string> {
private listeners: Map<EventType, Array<EventCallback>>;
constructor() {
this.listeners = new Map();
this.addListeners = this.addListeners.bind(this);
@piotrgrundas
piotrgrundas / 2019-https-localhost.md
Created November 16, 2020 10:58 — 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).

@piotrgrundas
piotrgrundas / Optional.ts
Created July 20, 2019 16:30 — forked from thiagoh/History|-1063032c|entries.json
typescript / javascript version of Optional
type Function<T, R> = (value: T) => R;
type Supplier<T> = () => T;
type Consumer<T> = (value: T) => void;
export interface OptionalMonad<T> {
filter: (predicate: (value?: T) => boolean) => OptionalMonad<T>;
ifPresent: (consumer: (value?: T) => void) => void;
isPresent: () => boolean;
map: <R>(mapper: (value?: T) => R) => OptionalMonad<R>;
flatMap: <R>(mapper: (value?: T) => OptionalMonad<R>) => OptionalMonad<R>;

Django ORM relations

1. Use select_related sparingly

Django's select_related results in an SQL JOIN.

It's very useful when fetching a one-to-one relation:

class User(Model):
@piotrgrundas
piotrgrundas / django-runserver-ssl.md
Created September 28, 2018 06:58 — forked from claudiosanches/django-runserver-ssl.md
Django - SSL with runserver

Instalation

[sudo] apt-get install stunnel

Configuration

cd path/to/django/project
@piotrgrundas
piotrgrundas / mysql-docker.sh
Created March 12, 2018 09:16 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@piotrgrundas
piotrgrundas / Install Spotify (v 0.9.17) on Fedora 64-bit
Created February 4, 2018 22:59 — forked from olejon/Install Spotify 0.9 on Fedora 64-bit
Install Spotify (v 0.9.17) on Fedora 64-bit
# START GUIDE
# Remember to read the comments if you have problems
# I can assure you that the Dropbox files belong to me and are extracted from official Ubuntu packages
# Make sure you copy the whole lines into Terminal. Each command is on one line.
# Open Terminal and become root
sudo -s
#!/usr/bin/python
# -*-coding:Utf-8 -*
import json
import os
import pickle
import sys
import time
import urllib
import requests
from io import open as iopen
@piotrgrundas
piotrgrundas / webpack.config.js
Created June 25, 2017 18:50
webpack.config.js
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var webpack = require('webpack');
var config = require('./config');
module.exports = {
@piotrgrundas
piotrgrundas / README.md
Created September 4, 2016 06:06 — forked from jimothyGator/README.md
Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}
cd /usr/local/etc/nginx/sites-enabled
ln -s ../sites-available/default.conf
ln -s ../sites-available/default-ssl.conf

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default.conf and default-ssl.conf to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/