Skip to content

Instantly share code, notes, and snippets.

@OpenGrid
OpenGrid / 2FA.md
Last active September 16, 2015 12:57
How to install 2FA authentication along with SSH key on Ubuntu 14.04

IMPORTANT never end your ssh session before the configuration is complete because you may loose the possibility to access your server

Install libpam-google-authenticator

apt-get install libpam-google-authenticator

Add you Google authenticator account by running:

google-authenticator

Verifying myself: My Bitcoin username is +opengrid. https://onename.io/opengrid
@OpenGrid
OpenGrid / primes.js
Last active December 19, 2015 00:49
Simple Prime Sieve
function getPrimes(howMany) {
var primes = [], isPrime, primesCount = 0, candidate, primeIndex;
for (candidate = 2; primesCount < howMany; candidate++) {
for(primeIndex = 0, isPrime = true;
primeIndex < primesCount && primes[primeIndex] <= Math.sqrt(candidate) && isPrime;) {
isPrime = (candidate % primes[primeIndex++] === 0) ? false : true;
}
if(isPrime === false) {
@OpenGrid
OpenGrid / primes.js
Last active December 19, 2015 00:18
Estimate nth prime number value
var nthEstimate = function(N) {
// http://en.wikipedia.org/wiki/Rosser%27s_theorem
return ~~(N * (Math.log(N) + Math.log(Math.log(N-1))));
}
@OpenGrid
OpenGrid / isNIPvalid.js
Created August 3, 2012 21:54
Validate NIP
/*
Check for validity of polish VAT ID number: NIP
*/
function NIPIsValid(nip) {
var weights = [6, 5, 7, 2, 3, 4, 5, 6, 7];
nip = nip.replace(/[\s-]/g, '');
if (nip.length == 10 && parseInt(nip, 10) > 0) {
var sum = 0;
@OpenGrid
OpenGrid / twitter-bootstrap-forms-responsive.css
Created July 24, 2012 15:19
Twitter Bootstrap form-horizontal css for form for two column layout
@media (max-width: 980px) {
.form-horizontal .control-group > label {
float: none;
width: auto;
padding-top: 0;
text-align: left;
}
.form-horizontal .controls {
margin-left: 0;
}
@OpenGrid
OpenGrid / Stone wall.js
Created June 28, 2012 16:12
Sigma 2012 Codility Programming Certificate Solution
/* http://blog.codility.com/2012/06/sigma-2012-codility-programming.html */
function stone_wall ( H ) {
var blocks = 0, stack = [], m, stack_length = 0;
for(m in H) {
// I use stack to remember all previous skyline levels
while(stack_length > 0 && stack[stack_length - 1] > H[m]) {
stack_length -= 1;
blocks += 1;
@OpenGrid
OpenGrid / dabblet.html
Created February 14, 2012 23:11 — forked from anonymous/dabblet.html
Untitled
<div style="width:800px;align:center;" width="800">
<h2 style="font-family:'Palatino Linotype', 'Book Antiqua', 'Palatino', 'Serif';text-align:center;font-weight:normal;">Bezpłatne spotkanie z ekspertem-projektantem DEKORADNIKA</h2>
<p style="font-family:'Palatino Linotype', 'Book Antiqua', 'Palatino', 'Serif';text-align:center;">
<strong>"Grafika w domu. Fotografia, mapy i inne druki w aranżacji wnętrza”</strong>
</p>
<p style="font-family:'Palatino Linotype', 'Book Antiqua', 'Palatino', 'Serif';text-align:justify;">
Jak ciekawie wyeksponować ukochaną fotografię?
Jak zaprezentować mapę lub inną zabytkową
grafikę?
@OpenGrid
OpenGrid / dabblet.html
Created February 14, 2012 21:14 — forked from anonymous/dabblet.html
Untitled
<div style="width:800px;align:center;" width="800">
<h2 style="font-family:'Palatino Linotype', 'Book Antiqua', 'Palatino', 'Serif';text-align:center;font-weight:normal;">Bezpłatne spotkanie z ekspertem-projektantem DEKORADNIKA</h2>
<p style="font-family:'Palatino Linotype', 'Book Antiqua', 'Palatino', 'Serif';text-align:center;">
<strong>"Grafika w domu. Fotografia, mapy i inne druki w aranżacji wnętrza”</strong>
</p>
<p style="font-family:'Palatino Linotype', 'Book Antiqua', 'Palatino', 'Serif';text-align:justify;">
Jak ciekawie wyeksponować ukochaną fotografię?
Jak zaprezentować mapę lub inną zabytkową
grafikę?
@OpenGrid
OpenGrid / gist:1620783
Created January 16, 2012 13:07
Impress.js mouse wheel event for changing slides
document.addEventListener("mousewheel", function( event ) {
next = steps.indexOf( active ) - event.wheelDelta / Math.abs(event.wheelDelta);
next = next >= 0 ? steps[ next ] : steps[ steps.length-1 ];
select(next);
}, false);