Skip to content

Instantly share code, notes, and snippets.

# @author godmar
from math import sqrt, ceil
n = int(raw_input())
a = map(int, raw_input().split())
sn = int(ceil(sqrt(n)))
buckets = [set(a[sn*i:sn*(i+1)]) for i in range(n/sn)]
q = int(raw_input())
"""
From: http://www.xs4all.nl/~rjoris/maximummatching.html
"""
"""Weighted maximum matching in general graphs.
The algorithm is taken from "Efficient Algorithms for Finding Maximum
Matching in Graphs" by Zvi Galil, ACM Computing Surveys, 1986.
It is based on the "blossom" method for finding augmenting paths and
the "primal-dual" method for finding a matching of maximum weight, both
@godmar
godmar / state.patch
Created March 8, 2018 16:59
This patch would link menu items to navigation states. If a state is already defined, the menu item would be { state: "nameofstate", label: "Menu Label" } and then the state would be looked up and the item's path set. Otherwise, it's backwards compatible with what you had before.
diff --git a/src/app/app.js b/src/app/app.js
index 160ad4a..62e6e13 100644
--- a/src/app/app.js
+++ b/src/app/app.js
@@ -359,25 +359,29 @@ import login_template from '../templates/login.html';
});
}
- config.nav_targets.topbar.forEach(function (item) {
- // add the routes from config.
@godmar
godmar / socket.patch
Created April 30, 2018 03:32
patch for socket.c that turns on TCP_NODELAY
diff --git a/src-solution/socket.c b/src-solution/socket.c
index 112e12b..6f0c402 100644
--- a/src-solution/socket.c
+++ b/src-solution/socket.c
@@ -13,6 +13,7 @@
#include <sys/sendfile.h>
#include <netdb.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <errno.h>
Petronila Pando  
Jeramy Jarrett  
Mitsue Mandel  
Alfonso Able  
Rae Rubalcava  
Ezra Edison  
Dierdre Demeo  
Marnie Mendes  
Velda Vogel  
Eve Eller  
@godmar
godmar / wasm-ld.deadlock.txt
Created November 12, 2019 17:47
The copied and pasted fragments below show what happens when wasm-ld locks up in eosio.cdt 1.6.1
Below is a backtrace of the threadpool-related deadlock that occurs in eosio.cdt 1.6.1 while linking with parallel linking enabled.
I've also included the relevant code sections in LLVM and the fix.
(gdb) attach 28855
Attaching to program: /usr/opt/eosio.cdt/1.6.1/bin/wasm-ld, process 28855
[New LWP 28856]
[New LWP 28857]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
#include <bits/stdc++.h>
using namespace std;
namespace std {
template<typename S1, typename S2> struct hash<pair<S1, S2>>
{
size_t operator()(pair<S1, S2> const& p) const noexcept
{
size_t const h1 ( std::hash<S1>{}(p.first) );
size_t const h2 ( std::hash<S2>{}(p.second) );
#!/usr/bin/python
# n-m nim
if True:
M, N = 3, 10
else:
M, N = 2, 2
def mex(S):
i = 0
import 'package:objd/core.dart';
class SummonOnlyOnce extends Widget {
Condition preCondition;
Summon summon;
String randomtag;
SummonOnlyOnce(Condition this.preCondition, Summon this.summon) {
this.randomtag = 'F3AAEC1'; // XXX: find out how to make random tag in dart
}
@godmar
godmar / map.js
Created June 18, 2020 00:36
output is:
countries = [
{ country: "US", rank: 3 },
{ country: "US", rank: 4 },
{ country: "UK", rank: 3 },
{ country: "UK", rank: 3 },
{ country: "Germany", rank: 7 },
];
let o1 = Object.fromEntries(countries.map(c => [c.country, 1]));