Skip to content

Instantly share code, notes, and snippets.

View kjvalencik's full-sized avatar

K.J. Valencik kjvalencik

  • 1Password
  • Baltimore, MD
View GitHub Profile
### Keybase proof
I hereby claim:
* I am kjvalencik on github.
* I am kjvalencik (https://keybase.io/kjvalencik) on keybase.
* I have a public key whose fingerprint is A38B A193 03A3 C812 243B DFE7 1C89 98B6 F905 0CC9
To claim this, I am signing this object:
@kjvalencik
kjvalencik / .gitignore
Last active March 8, 2016 17:28
Kafka Partitioner Test
node_modules/
npm-debug.log
.m2/
@kjvalencik
kjvalencik / promiseExtensions.js
Last active February 21, 2016 00:34
Extended version of built-in v8 promises
// TODO: Implement `forEach` and `reduce`
class P extends Promise {
constructor(fn) {
super(fn);
}
tap(fn) {
return this.then(res => {
return Promise
@kjvalencik
kjvalencik / promiseRetry.js
Last active August 29, 2015 14:22
Bluebird Promise Re-try
function promiseRetry(_fn, _attempts, backoff /* , errTypes */) {
var fn = Bluebird.method(_fn),
attempts = parseInt(_attempts, 10);
var argsLen = arguments.length,
retryLen = promiseRetry.length,
catchArgs = new Array(Math.max(1, argsLen - retryLen + 1));
for (var i = retryLen; i < argsLen; i += 1) {
catchArgs[i - retryLen] = arguments[i];
@kjvalencik
kjvalencik / distractionFreeWikipedia.css
Created November 10, 2014 17:30
Distraction free Wikipedia
#content a[href^="/"]:not([href^="//"]) {
pointer-events: none;
color: inherit;
}
@kjvalencik
kjvalencik / mathPuzzle.js
Created October 21, 2014 15:11
This could be solved with linear algebra, but it only took a few minutes to write a brute force script.
/*
Three farmers were selling chickens at the local market.
One farmer had 10 chickens to sell, another had 16 chickens to sell, and the last had 26 chickens to sell.
In order not to compete with each other, they agreed to all sell their chickens at the same price.
But by lunchtime, they decided that sales were not going so well, and they all decided to lower their
prices to the same lower price point. By the end of the day, they had sold all their chickens. It turned
out that they all collected the same amount of money, $35, from the day's chicken sales.
What was the price of the chickens before lunchtime and after lunchtime?
*/
@kjvalencik
kjvalencik / lodash-es5-shim.js
Created April 30, 2014 17:20
Utilize lodash for polyfill of methods required by React
/* global _ */
// Based on https://github.com/es-shims/es5-shim
;(function () {
"use strict";
/* Provides the following polyfills
*
* Array.isArray
* Array.prototype.forEach
* Array.prototype.indexOf
@kjvalencik
kjvalencik / patchJava64.sh
Created March 27, 2014 13:15
Replace the 64-bit java binary with a shell script that will use the 32-bit binary iif Juniper Network Connect is being loaded.
#!/bin/bash
JAVA=$(readlink -f `which java`)
JAVA32=$(echo $JAVA | sed 's/\/jvm\//\/jvm\/ia32-/ig')
if [ -a $JAVA.orig ]
then
echo "Binary already patched"
else
echo "Patching binary..."
@kjvalencik
kjvalencik / coinFlipExperiment.js
Created January 6, 2014 00:28
Coin flip probability
// You have 1,024 coins. One of those coins is double headed,
// but the rest are fair. You pick a coin at random and flip
// it 10 times and get 10 heads. What is the probability that
// the next flip will be heads?
// Constants
var TOTAL_COINS = 1024,
NUM_DOUBLE = 1,
NUM_FLIPS = 10,
PROB_FAIR = .5,
@kjvalencik
kjvalencik / upgradeUbuntu
Last active December 14, 2015 12:59
Upgrading Ubuntu 11.10 to 12.04 on an old OpenVZ kernel
# update
apt-get update
apt-get upgrade
# update manager for dist upgrades
apt-get install update-manager-core
# install recompiled libc, not available in repo
mkdir updateOpenVZ