Skip to content

Instantly share code, notes, and snippets.

@peta
peta / mysql-mirror.sh
Created December 13, 2012 15:56
Simple bash script for migrating MySQL databases (including all associated user accounts) to a remote server. Use it with care because the usage of mysqldump in this script solely relies on default values which may vary greatly on your machine. (mysqldump is a powerful tool, so don't miss `man mysqldump`).
#!/bin/bash
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# Source: http://www.cyberciti.biz/tips/move-mysql-users-privileges-grants-from-one-host-to-new-host.html
# Author Vivek Gite <vivek@nixcraft.com>,
# Peter Geil <code@petergeil.name>
# ------------------------------------------------------------
# SETME First - local mysql user/pass
_lusr="src-db-user"
_lpass="src-db-pw"
@peta
peta / fm4-grabber.rb
Last active June 25, 2020 20:25
Die Jungs von ORF/FM4/APA haben offenbar den Publishingworkflow und die Integration der FM4oD Mitschnitte auf fm4.orf.at überarbeitet -- und somit mein altbewährtes Grabber-Bashskript unbrauchbar gemacht. Die neue Lösung ist etwas komplexer, weswegen ich das Skript auch mit Ruby anstatt Bash umgesetzt habe, aber funktioniert dennoch gewohnt zuve…
#!/usr/bin/env ruby
# encoding: UTF-8
require 'uri'
require 'open-uri'
require 'json'
require 'nokogiri'
class PodcastGrabber
Import-Module Microsoft.Xrm.Data.Powershell
$conn = Connect-CrmOnlineDiscovery -InteractiveMode
$req = New-Object Microsoft.Xrm.Sdk.OrganizationRequest
$req.RequestName = "RetrieveSolutionMetadataForComponent"
# Entity "account"
[string[]]$colNames = "entityid"
[string[]]$colValues = "70816501-edb9-4740-a16c-6a5efbc05d84"
@peta
peta / demo-grammar.tmProperties
Last active March 21, 2020 04:58
Regex design pattern for Textmate language grammars. An absolutely cool feature of PCRE (even supported by Oniguruma) are named subexpression calls. Allowing for recursive matching while preserving (atomic) contexts at every recursion level in form of named match results. However, there is no light without shadow: When no multiline matches can b…
myPattern = {
name = 'meta.spec.triples';
begin = '(?x)
(?<subject> \g<iri> | \g<BlankNode> | \g<collection> ){0}
(?<iri> \g<IRIREF> | \g<PrefixedName> ){0}
(?<IRIREF> \< (?:[^\x00-\x20\<\>\\\"\{\}\|\^`] | (?:\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8}))* \> ){0}
(?<PrefixedName> \g<PNAME_LN> | \g<PNAME_NS> ){0}
(?<PNAME_LN> (\g<PNAME_NS>) ( (?: [\p{L}\p{M}_] | [:0-9] | %[0-9A-Fa-f]{2} | [\\_~.\-!$&''\(\)*+,;=/?#@%] ) (?:(?:[\p{L}\p{M}_\-0-9\u00B7\u0300-\u036F\u203F-\u2040] | [:.] | %[0-9A-Fa-f]{2} | [\\_~.\-!$&''\(\)*+,;=/?#@%])* (?:[\p{L}\p{M}_\-0-9\u00B7\u0300-\u036F\u203F-\u2040] | : | %[0-9A-Fa-f]{2} | [\\_~.\-!$&''\(\)*+,;=/?#@%])) )? ){0}
(?<PNAME_NS> (?: [\p{L}\p{M}] (?:(?:[\p{L}\p{M}_.\-0-9\u00B7\u0300-\u036F\u203F-\u2040])* [\p{L}\p{M}_\-0-9\u00B7\u0300-\u036F\u203F-\u2040] )? )? \: ){0}
(?<BlankNode> \g<BLANK_NODE_LABEL> | \g<ANON> ){0}
declare @n char(1)
set @n = char(10)
declare @stmt nvarchar(max)
-- procedures
select @stmt = isnull( @stmt + @n, '' ) +
'drop procedure [' + schema_name(schema_id) + '].[' + name + ']'
from sys.procedures
@peta
peta / README.md
Last active October 30, 2018 09:47
Testcase: Bug in Dynamics CRM Web API (OData 4.x) for RetrieveMultiple by FetchXML

Description

While migrating some form logic which used to execute a FetchXML query and react to the result accordingly, from XrmServiceToolkit to the native OData Web API in 8.2, I encountered some weird platform behaviour. Everytime the LIKE filter condition contained a part of the number series 123456789 beginning at number 1 (like for example %123%), the OData service yields a 500 server error for no obvious reason.

Outcome

This bug was solved in latest 9.1 version (or earlier), event in the Web API endpoint version 8.1

Steps to reproduce

@peta
peta / url_regex.js
Last active October 24, 2018 15:18
var urlParseRegex = /^(?:(?:(([^:\/#\?]+:)?(?:(?:\/\/)(?:(?:(?:([^:@\/#\?]+)(?:\:([^:@\/#\?]*))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((?:\/?(?:[^\/\?#]+\/+)*)(?:[^\?#]*)))?(\?[^#]+)?)(#.*)?/;
var results = urlParseRegex.exec('http://user:pass@host.com:81/directory/file.ext?query=1#anchor');
// Variable "results" now contains the fragments in the following order
var keysInOrderTheyAppear = [
"href", // http://user:pass@host.com:81/directory/file.ext?query=1#anchor
"origin", // http://user:pass@host.com:81
"protocol", // http:
"username", // user
@peta
peta / snippet.cs
Last active September 5, 2018 09:00
Automatically adjust batch-size in ExecuteMultipleRequests
public static IEnumerable<ExecuteMultipleResponse> RunMultipleRequestInSteps(ICrmConnection crmConnection, IEnumerable<OrganizationRequest> organizationRequestList, ExecuteMultipleRequest executeMultipleRequest, bool retryOnBatchSizeLimit = true)
{
// Calculate totalElements, elementToProcess and steps
var totalElements = organizationRequestList.Count();
var steps = (totalElements <= MaxBatchRequestSize) ? 1 : Math.Ceiling((double) totalElements / MaxBatchRequestSize);
var responseList = new List<ExecuteMultipleResponse>();
for (int i = 0; i < steps; i++)
{
// Get current requests to process
using Microsoft.Xrm.Sdk;
namespace Foo.CRM.Integration.Data.Helper
{
public static class XrmSdkExtensions
{
/// <summary>
/// Retrieve formatted value for given key and optionally return default value when key was not found in collection. This method will
/// not yield any exceptions when a requested key was not found.
/// </summary>
@peta
peta / example-1.js
Created March 14, 2018 10:13
Some random examples showing simple JavaScript Promise usage patterns, I wrote together during a frontend dev course I gave back in 2015
// Example 1 -- Prom-what??!#
//===== Callback-style
// Nested async foo as we know and love it
// Output from previous async call becomes input of the one called next
giveBirthTo(function (peter) {
growUp(peter, function (grownUpPeter) {
travelTheWorld(grownUpPeter, function (culturedPeter) {
marryAndHaveKids(culturedPeter, function (seniorPeter) {