Skip to content

Instantly share code, notes, and snippets.

View darkleaf's full-sized avatar

Mikhail Kuzmin darkleaf

View GitHub Profile
#!/usr/bin/env python3
from yaml import load, dump, FullLoader
import sys
file_name = sys.argv[1]
def process_ua(data):
for node in data:
if 'family_replacement' not in node:
@Ivana-
Ivana- / take-first-sorted-by.clj
Created November 26, 2020 17:25
Lazysecs efficient reducer, which returns n first elements of sequence, sorted by keyfn & comp
(defn take-first-sorted-by
"Performs the same result as (take n (sort-by keyfn comp coll))
but more efficient in terms of time and memory"
([n keyfn coll] (take-first-sorted-by n keyfn compare coll))
([n keyfn ^java.util.Comparator comp coll]
(if (pos? n)
(let [m ^java.util.TreeMap (java.util.TreeMap. comp)
m-size (volatile! 0)
;; if it is guaranteed that (keyfn v) will be unique for all v in coll
;; we can attach :unique? key to keyfn meta and algorythm will use single val map
#!/bin/bash
# Custom scripts here
echo "This is an extended entrypoint!"
# Run the original entrypoint located at
# /docker-entrypoint.sh
exec /docker-entrypoint.sh "$@"
@favila
favila / datomic-counter.clj
Created September 29, 2017 16:23
Demonstrate the creation and use of an auto-increment counter (with nonce) in datomic
(require '[datomic.api :as d])
(d/create-database "datomic:mem://counter-example")
;=> true
(def c (d/connect "datomic:mem://counter-example"))
;=> #'user/c
;; The essential features of creating and using an auto-increment counter in datomic:
;;
;; 1. A counter entity must store the current value and a nonce.
@bhb
bhb / test_helper.clj
Last active March 6, 2019 10:51
Test helpers when using clojure.spec
(ns foo.test-helper
(:require [clojure.spec :as s]
[clojure.spec.test :as st]
[clojure.string :as str]
[clojure.test :refer :all]
[clojure.test.check.generators :as gen]
[clojure.test.check.random :refer [IRandom]]
[clojure.test.check.rose-tree :as rose]))
(defn instrument-all
@PaulMaynard
PaulMaynard / MapProxy.js
Created October 18, 2014 16:08
ES6 Map Accessor Proxy
/**
* Proxy for accessing ES6 Maps like objects.
* Usage example:
*
* var p = new MapProxy();
* p['key'] = 'value';
* if ('key' in p) {
* console.log(p.key);
* }
* delete p.key;
@cpjolicoeur
cpjolicoeur / gist:3590737
Created September 1, 2012 23:15
Ordering a query result set by an arbitrary list in PostgreSQL

I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.

Problem Description

Most of us have work on projects at some point where we have needed to have ordered lists of objects. Whether it be a to-do list sorted by priority, or a list of documents that a user can sort in whatever order they want.

A traditional approach for this on a Rails project is to use something like the acts_as_list gem, or something similar. These systems typically add some sort of "postion" or "sort order" column to each record, which is then used when querying out the records in a traditional order by position SQL query.

This approach seems to work fine for smaller datasets, but can be hard to manage on large data sets with hundreds (or thousands) of records needing to be sorted. Changing the sort position of even a single object will require updating every single record in the database that is in the same sort group. This requires potentially thousands of wri

@equivalent
equivalent / app-assets-javascript-datepicker.js.coffee
Created July 5, 2012 12:24
Simple Form custom input for "Datepicker for Twitter Bootstrap" running under Ruby on Rails with Ransack search
# install and make run basic bootstrap date-picker functionality described here http://www.eyecon.ro/bootstrap-datepicker/
# app/assets/javascript/datepicker.js.coffee
$(document).on 'pageChanged', ->
# datepicker for simple_form & Ransack
$(".custom_datepicker_selector").datepicker().on 'changeDate', (en) ->
correct_format = en.date.getFullYear() + '-' + ('0' + (en.date.getMonth() + 1)).slice(-2) + '-' + ('0' + en.date.getDate()).slice(-2) # date format yyyy-mm-dd
$(this).parent().find("input[type=hidden]").val(correct_format)
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session