Skip to content

Instantly share code, notes, and snippets.

View mormegil-cz's full-sized avatar

Petr Kadlec mormegil-cz

View GitHub Profile
@mormegil-cz
mormegil-cz / gist:4080746
Created November 15, 2012 19:39
Multi-threaded cookie management
private readonly Dictionary<string, Cookie> globalCookies = new Dictionary<string, Cookie>();
public void DoRequest(Uri uri)
{
var localCookies = new CookieContainer();
lock(globalCookies)
{
foreach(var cookie in globalCookies)
{
localCookies.Add(cookie.Value);
@mormegil-cz
mormegil-cz / PredicateLogicTests.cs
Created January 30, 2013 15:26
unit test of predicate logic :-)
[TestFixture]
public class PredicateLogicTests
{
[Test]
public void TestNegationOfUniversalQuantifier()
{
var empty = new int[0];
var allOdd = new[] { 1, 3, 5 };
var allEven = new[] { 2, 4, 6 };
var allNumbers = new[] { 1, 2, 3 };
void CountAccents(string input)
{
if (input.Length != 0 && !Char.IsWhiteSpace(input[input.Length - 1])) input = input + " ";
int wordsTotal = 0;
int wordsOnlyLetters = 0;
int wordsAccented = 0;
int wordStart = 0;
bool hasAccent = false;
bool hasNonLetter = false;
Func<double, double> eval = r => Math.Asin(1 / (2 * r)) * r * r + Math.Sqrt(r * r - 0.25) / 2 - 0.5;
double left = 0.5;
double right = 1;
for(int i = 0; i < 100; ++i)
{
var mid = (left + right) / 2;
var midRes = eval(mid);
if (midRes < 0) left = mid;
else right = mid;
@mormegil-cz
mormegil-cz / CheckLangNames.php
Last active January 22, 2019 14:48
A check for language name differences between MediaWiki core and CLDR (via https://www.mediawiki.org/wiki/Extension:CLDR)
<?php
define('MW_PATH', '../../');
require(MW_PATH . 'languages/data/Names.php');
$coreLanguageNames = MediaWiki\Languages\Data\Names::$names;
echo "{|\n";
echo "! Lang !! In core !! In CLDR\n";
@mormegil-cz
mormegil-cz / IntrfTest.il
Created January 2, 2014 19:48
Static fields and methods in interfaces in CIL
// test at http://www.compileonline.com/compile_ilasm_online.php
.assembly IntrfTest {}
.assembly extern mscorlib {}
.method static void Main()
{
.entrypoint
.maxstack 1
call void IInterface::StaticMethod()
call void IInterface::StaticMethod()
@mormegil-cz
mormegil-cz / CodeBowlingReverse.cs
Created January 23, 2014 16:16
A “longest” implementation of a string reverse, per http://codegolf.stackexchange.com/q/19225/6532
This file has been truncated, but you can view the full file.
using System;
using System.Text;
class C
{
static void Main()
{
var c0 = Console.Read();
if (c0 > 0 && c0 != 13)
{
<?php
/**
* Simple emulation of ICU sortkeys for trivial strings (strings containing [A-Za-z0-9] only)
*
* See http://userguide.icu-project.org/collation/architecture#TOC-Sort-Keys
*/
function simple_sort_key($str)
{
@mormegil-cz
mormegil-cz / VolbyStatistiky.cs
Created September 29, 2014 19:33
Triviální statistické zpracování volebních dat z projektu Otevřené volby (ovolby.cz); v tomto případě zjištění rekordně nízkých účastí
// LINQPad C# Program
const int COL_VOLBY = 0;
const int COL_OBVOD = 1;
const int COL_OBEC = 3;
const int COL_K1_VOLICI = 6;
const int COL_K1_OBALKY = 7;
const int COL_K2_VOLICI = 10;
const int COL_K2_OBALKY = 11;
SELECT linksfromlist.pl_title, (SELECT COUNT(*) FROM pagelinks incominglinks WHERE incominglinks.pl_title=linksfromlist.pl_title AND incominglinks.pl_namespace=linksfromlist.pl_namespace AND incominglinks.pl_from_namespace=0) linkcount
FROM pagelinks linksfromlist
INNER JOIN page ON linksfromlist.pl_from=page_id
WHERE page_namespace=2 AND page_title='Vojtěch_Dostál/Pískoviště3'
AND linksfromlist.pl_namespace=0
ORDER BY linkcount DESC