Skip to content

Instantly share code, notes, and snippets.

Andrey Paramonov ndpar

Block or report user

Report or block ndpar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View openssl-ca.cnf
HOME = .
RANDFILE = $ENV::HOME/.rnd
####################################################################
[ ca ]
default_ca = CA_default # The default ca section
[ CA_default ]
default_days = 730 # how long to certify for
View crypto.rkt
#lang racket
(module+ test
(require rackunit))
(define ⊕ bitwise-xor)
(define hex
(curryr number->string 16))
@ndpar
ndpar / regex.groovy
Created Dec 20, 2017
URL Parser in Groovy
View regex.groovy
def subDomain = '(?i:[a-z0-9]|[a-z0-9][-a-z0-9]*[a-z0-9])' // simple regex in single quotes
def topDomains = $/
(?x-i : com \b # you can put whitespaces and comments
| edu \b # inside regex in eXtended mode
| biz \b
| in(?:t|fo) \b # backslash is not escaped
| mil \b # in dollar-slash strings
| net \b
| org \b
| [a-z][a-z] \b
View combinators.groovy
def Y = { f ->
{ x -> x(x) } { x -> f { y -> x(x)(y) } }
}
def triangular = Y { f ->
{ n -> n == 0 ? 0 : n + f(n - 1) }
}
triangular(3000)
@ndpar
ndpar / redefine.rkt
Last active Aug 29, 2015
How to redefine procedure in Racket.
View redefine.rkt
(define-syntax-rule
(redefine (f args ...) body ...)
(set! f (λ (args ...) body ...)))
(define (double x)
(+ x x))
(redefine (double x)
(* 2 x))
@ndpar
ndpar / rzip.rkt
Last active Aug 29, 2015
Reverse zip
View rzip.rkt
#lang racket
;; Inspired by SICP, chapter 5.2.2, and
;; https://www.youtube.com/watch?v=SrKj4hYic5A
(define (rzip c1 c2)
(let iter ([a c1] [z c2] [receive (λ (x y) y)])
(if (null? a)
(receive z '())
(iter (cdr a) z
@ndpar
ndpar / poker.clj
Last active Dec 16, 2015
Poker hand evaluator in different languages.http://en.wikipedia.org/wiki/List_of_poker_hands
View poker.clj
; https://github.com/ndpar/clojure/blob/master/src/dojo/poker.clj
; https://github.com/ndpar/clojure/blob/master/test/dojo/poker_test.clj
(defn card-ranks
"Return a vector of the ranks, sorted with higher first"
[hand]
(let [ranks (map #(->> % first str (.indexOf "--23456789TJQKA")) hand)
ranks (vec (sort > ranks))]
(if (= [14 5 4 3 2] ranks) [5 4 3 2 1] ranks)))
@ndpar
ndpar / zookeeper-init-ensemble.sh
Created Mar 7, 2013
Idempotent script that quickly (re)creates 3-node ZooKeeper ensemble on a single box for development purposes. http://ndpar.blogspot.com/2013/03/simple-zookeeper-cluster.html
View zookeeper-init-ensemble.sh
#!/bin/sh
cd /opt/zookeeper/zookeeper
rm -rf cluster
mkdir -p cluster/server{1,2,3}/{conf,data,logs}
cp conf/log4j.properties cluster/server1/conf/
cp conf/log4j.properties cluster/server2/conf/
cp conf/log4j.properties cluster/server3/conf/
@ndpar
ndpar / answers.py
Created Dec 13, 2012
Analyzing popularity on StackOverflow
View answers.py
import urllib2
import zlib
import json
import pymongo
import sys
URL = 'http://api.stackoverflow.com/1.1'
ANSWERS = URL + '/questions/{0}/answers'
def load_url(url):
@ndpar
ndpar / SolrExporter.groovy
Last active Nov 16, 2016
Export documents from Solr core to XML format
View SolrExporter.groovy
#!/usr/bin/env groovy
/**
* Usage: ./SolrExporter.groovy query url [url]
*
* ./SolrExporter.groovy "id:12345" "http://your.solr.host:8983/solr/core/"
*
* ./SolrExporter.groovy "id:12345" "http://old.solr.host:8983/solr/core/" "http://new.solr.host:8983/solr/core/"
*
*
You can’t perform that action at this time.