Skip to content

Instantly share code, notes, and snippets.

Avatar

Ondrej Medek xmedeko

View GitHub Profile
@xmedeko
xmedeko / htmlregex.js
Created Oct 16, 2019
HTML/XML manipulation by regular expressions in JavaScript (RegExp)
View htmlregex.js
/**
* 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 Jan 31, 2019
google locked_file to be used with the google-api-python-client.
View locked_file.py
# 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 Feb 6, 2018
Improved HttpRequestWithRetry for google-api-python-client
View google_api_http.py
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 Sep 13, 2018
WPF-MediaKit video screen grabbing helper.
View VideoScreenGrabber.cs
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 Dec 22, 2016
WPF Content control ignoring the content width. Suitable to force a TextBlock to wrap the text.
View Example.xaml
<!-- 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 Sep 21, 2016
Google Cloud Bucket: create explicit dirs
View gsmkdirs.sh
#!/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 Mar 20, 2016
Hack to get select columns for Dapper.Contrib ORM type
View DapperSelectColumns.cs
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)
{
@xmedeko
xmedeko / IpRange.java
Created Jan 29, 2016
IpRange parse and contains test
View IpRange.java
package org.xmedeko;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.logging.Logger;
/**
* IP range or just one IP address. The main method {@link #containsAddress(byte[])} tests if the given address is in the range.
*
@xmedeko
xmedeko / BatchInitalizer.java
Last active Dec 28, 2015
Simple helper to batch load of uninitialized LAZY relations in Hibernate entities.
View BatchInitalizer.java
package org.xmedeko;
import java.util.List;
import java.util.Set;
import org.hibernate.annotations.BatchSize;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import com.google.common.base.Preconditions;
@xmedeko
xmedeko / JLinkButton.java
Last active Dec 28, 2015
Java Swing JLinkButton draws a button like JLabel with blue color and underlined font on mouse hover. Disclaimer: inspired by a few others similar solutions.
View JLinkButton.java
import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.font.TextAttribute;
import java.util.Map;
import javax.swing.Action;
You can’t perform that action at this time.