Skip to content

Instantly share code, notes, and snippets.

@xmedeko
xmedeko / Volume.ahk
Last active March 21, 2023 07:02
AutoHotkey volume by Window key
#Requires AutoHotkey v2.0-
#SingleInstance Force
DEFAULT_VOLUME := 30
; Single press - mute, unmute. Double press - unmute and default volume.
#F1:: {
static winf1_presses := 0
if winf1_presses > 0 { ; Timer already started.
winf1_presses += 1
@xmedeko
xmedeko / index.html
Last active April 22, 2021 07:18
Electron window-all-closed BrowserWindow.getAllWindows bug
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<link rel="stylesheet" type="text/css" href="./styles.css">
</head>
<body>
<h1>Hello World!</h1>
<p> Close the window and check the console output. </p>
@xmedeko
xmedeko / index.html
Last active March 12, 2021 14:09
Electron openPath error dialog minimized
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'">
<title>openPath error dialog minimized</title>
</head>
<body>
@xmedeko
xmedeko / htmlregex.js
Created October 16, 2019 11:51
HTML/XML manipulation by regular expressions in JavaScript (RegExp)
/**
* JS remove HTML/XML attribure regexp.
*/
function removeAttribute(html, tagName, attrName) {
return html.replace(new RegExp(`(<${tagName}.*?)\\s+${attrName}=(["']).*?\\2(.*?>)`, 'gmi'), '$1$3');
}
@xmedeko
xmedeko / locked_file.py
Last active January 31, 2019 15:05
google locked_file to be used with the google-api-python-client.
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@xmedeko
xmedeko / google_api_http.py
Last active February 6, 2018 08:20
Improved HttpRequestWithRetry for google-api-python-client
from googleapiclient.http import HttpRequest
class HttpRequestWithRetry(HttpRequest):
"""googleapiclient HttpRequest with default num_retries.
Google REST API HTTP 500 error is flood protection and the request should be retried with an exponential backoff.
The execute(num_retries) already implements it.
This class is just a simplification to not need to specify num_retries for every execute call.
@xmedeko
xmedeko / VideoScreenGrabber.cs
Last active September 13, 2018 19:13
WPF-MediaKit video screen grabbing helper.
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Interop;
using WPFMediaKit.DirectShow.Controls;
using WPFMediaKit.DirectShow.MediaPlayers;
namespace Test_Application
{
@xmedeko
xmedeko / Example.xaml
Last active December 22, 2016 12:23
WPF Content control ignoring the content width. Suitable to force a TextBlock to wrap the text.
<!-- Especially usefull when placed inside Window and ScrollViewer -->
<myc:IgnoreWidthControl>
<TextBlock Text="Very long text which has to be wrapped. Yeah, it must be wrapped." TextWrapping="Wrap" />
</myc:IgnoreWidthControl>
@xmedeko
xmedeko / gsmkdirs.sh
Created September 21, 2016 09:27
Google Cloud Bucket: create explicit dirs
#!/bin/bash
##
## Creates explicit dirs on the bucket
##
function print_help() {
echo "Usage:" $(basename $0) bucket_mounted_dir
exit 1
}
@xmedeko
xmedeko / DapperSelectColumns.cs
Created March 20, 2016 17:59
Hack to get select columns for Dapper.Contrib ORM type
namespace Helpers
{
public static class DapperSelectColumns
{
/// <summary>
/// Hack to string for select statement for the given ORM type.
/// </summary>
/// <param name="ormType"></param>
public static string SelectClause(Type ormType, string alias)
{