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())
/*
* Can we really implement anything, no matter how inefficient, and have it pass
* just because it's frigging C++???
*/
#include <bits/stdc++.h>
using namespace std;
int
main()
{
@godmar
godmar / justbinsearch.py
Created October 17, 2017 19:07
This times out....
n = int(raw_input())
nums = list(map(int, raw_input().split()))
q = int(raw_input())
for _ in xrange(q):
line = list(map(int, raw_input().split()))
idx = line[0]
numzz = set(line[2:])
lo, hi, count = idx-1, n, 0
/*
* Can we really implement anything, no matter how inefficient, and have it pass
* just because it's frigging C++???
*/
#include <bits/stdc++.h>
using namespace std;
class Node {
int start, end;
set<int> rset;
@godmar
godmar / MaximalSequence.java
Last active October 17, 2017 16:32
This code implements a "ReadOnlySegment" tree for a known array of values. It supports a (range combining) query like a normal segment tree, although this is not used in this problem. In addition, it implements Eric's 'countLeqThan' method that determines the maximum continous range left of a start index (leftbound) that is less than a given max…
/*
* Maximal sequence inspired by Eric's segment tree idea.
* Using Hassan's original segment tree code implementation.
*
* @author godmar
*/
import java.util.*;
public class MaximalSequence
{
@godmar
godmar / mstwithiterator.java
Last active April 21, 2017 00:05
Kruskal can break early once the graph is connected in which case it doesn't have to process all edges. Thus, in cases like here, where the edges are dynamically ordered, not all edges may need to be prepared. I tested this idea below. It cuts the runtime drastically for many of the test cases (and I verified that, many break after only a few pe…
/*
Kruskal can break early once the graph is connected in which case it doesn't have to process
all edges. Thus, in cases like here, where the edges are dynamically ordered, not all edges
may need to be prepared. I tested this idea below. It cuts the runtime drastically for many
of the test cases (and I verified that, many break after only a few percent of the edges).
It doesn't cut worst case time because for some of the larger tests, the graph isn't
connected until over 99% of the edges are considered. But, it also doesn't hurt.
In fact, Kattis runtime was .1s faster than the eager, array-based version, so
the use of the Iterator doesn't hurt. Note that the solve() method could also be
written to take an Iterator, which would avoid the somewhat random construction
@godmar
godmar / gist:fb5057897eca1b3d8b262bedb2a63037
Created December 1, 2016 19:27
incomplete webpack2 patch
diff --git a/config/webpack.config.prod.js b/config/webpack.config.prod.js
index df6db14..6970253 100644
--- a/config/webpack.config.prod.js
+++ b/config/webpack.config.prod.js
@@ -43,6 +43,8 @@ if (env['process.env'].NODE_ENV !== '"production"') {
throw new Error('Production builds must have NODE_ENV=production.');
}
+console.log(`resolve path: ${paths.nodePaths}`)
+
@godmar
godmar / gist:921a7c3b2a59c5ac5e00a11281af92d5
Created November 22, 2016 14:49
node_modules content of util and events subdirs
$ tree node_modules/util node_modules/events
node_modules/util
├── LICENSE
├── node_modules
│   └── inherits
│   ├── inherits_browser.js
│   ├── inherits.js
│   ├── LICENSE
│   ├── package.json
│   ├── README.md
@godmar
godmar / gist:b04b96e9648f8464c983c754482af8ab
Created November 22, 2016 14:39
npm list after 0.7.0-alpha.9c45b252
fail-event-emitter2@0.1.0 /home/gback/fail-event-emitter2
├─┬ react@15.4.0
│ ├─┬ fbjs@0.8.6
│ │ ├── core-js@1.2.7
│ │ ├─┬ isomorphic-fetch@2.2.1
│ │ │ └─┬ node-fetch@1.6.3
│ │ │ ├─┬ encoding@0.1.12
│ │ │ │ └── iconv-lite@0.4.15
│ │ │ └── is-stream@1.1.0
│ │ └── ua-parser-js@0.7.12
@godmar
godmar / LoginForm.patch
Created November 11, 2016 15:47
A patch to make LoginForm dumb
diff --git a/src/containers/forms/LoginForm.js b/src/containers/forms/LoginForm.js
index 5353cef..7c57b50 100644
--- a/src/containers/forms/LoginForm.js
+++ b/src/containers/forms/LoginForm.js
@@ -4,7 +4,7 @@ import { Alert, Button, ButtonToolbar,
Form, FormGroup } from 'react-bootstrap';
import { propTypes as reduxFormPropTypes } from 'redux-form';
-import connectedForm from './connectedForm';
+import { reduxForm } from 'redux-form';