Skip to content

Instantly share code, notes, and snippets.

@samupl
samupl / vue-webcomponent-shadow-root-fix.vuetify.js
Created September 2, 2022 08:42
Vuetify Shadow DOM root fix, when target built is web component
// Vuetify monkey patch to make sure querySelector works with shadow dom roots
// when used by a web component.
const { querySelector } = document;
const WEB_COMPONENTS_PATH = '/static/js/web-components/';
document.querySelector = function (selector) {
// We're only monkey patching if data-app is being selected.
if (selector !== "[data-app]") return querySelector.call(this, selector);
// Get a list of all our web-components
@samupl
samupl / youtube-t-removal.user.js
Created August 29, 2018 09:27
Remove youtube's ?t parameter
// ==UserScript==
// @name youtube t removal
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Remove youtube's ?t parameter
// @author Jakub Szafrański
// @match https://www.youtube.com/watch*
// @grant none
// ==/UserScript==
// ==UserScript==
// @name Clippy github
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Github merge conflict clippy
// @author Jakub Szafrański
// @match https://github.com/*/pull/*
// @grant none
// ==/UserScript==
@samupl
samupl / workon_venv_dir.sh
Created June 9, 2017 07:16
ZSH: Virtualenvwrapper automatic virtualenv workon when entering project directory
# Based on https://hmarr.com/2010/jan/19/making-virtualenv-play-nice-with-git/
# Modified to work with ZSH
function workon_cwd {
GIT_DIR=`git rev-parse --git-dir 2> /dev/null`;
if [[ "$?" == 0 ]]; then
GIT_DIR=`\cd $GIT_DIR; pwd`
PROJECT_ROOT=`dirname "$GIT_DIR"`
ENV_NAME=`basename "$PROJECT_ROOT"`
@samupl
samupl / scrum_master.py
Created April 1, 2016 08:30
Automated scrum master, v0.1-alpha! :)
# http://www.agile247.pl/aplikacja-zastapi-prace-scrum-masterow-nowy-produkt-od-tworcow-scruma/
# :-)
import random
import subprocess
import time
def random_question(questions):
return random.choice(questions)
@samupl
samupl / using_request_post_or_none.py
Created February 25, 2016 20:37 — forked from pylemon/using_request_post_or_none.py
django: using(request.POST or None) hack in views | advanced forms usage
# simple form usage in view
def my_view(request, template_name='home.html'):
# sticks in a POST or renders an empty form
form = MyForm(request.POST or None)
if form.is_valid():
do_something()
return redirect('/')
return render_to_response(template_name, {'form':form})
# form with files
@samupl
samupl / ajax_put_download.js
Created October 12, 2015 18:50
Download file (PDF) from PUT request, if for any reason you have to...
var putData = {}; // In my example this was from a form
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'SOME_URL', true);
xhr.responseType = 'arraybuffer';
// xhr.setRequestHeader('X-CSRFToken', getCookie('csrftoken')); // Django CSRF
xhr.send(JSON.stringify(putData));
xhr.onload = function(e) {
// Convert the array buffer to base64 and get the filename from headers.
// This obviously expects the Content-Disposition header with a filename attribute.
var arr = new Uint8Array(this.response);

Keybase proof

I hereby claim:

  • I am samupl on github.
  • I am samu (https://keybase.io/samu) on keybase.
  • I have a public key whose fingerprint is CA73 97E9 411C FADF 5CA9 9C15 CE48 1B9F CA80 9A4F

To claim this, I am signing this object: