Skip to content

Instantly share code, notes, and snippets.

View urmastalimaa's full-sized avatar

Urmas Talimaa urmastalimaa

  • Glia Inc
  • Tartu, Estonia
View GitHub Profile
@urmastalimaa
urmastalimaa / uuid.js
Created December 30, 2021 13:43
v4 UUID generation using crypto.getRandomValues
export default function () {
// returns an RFC 4122 compliant UUID using the crypto API
// Based on https://gist.github.com/bentranter/ed524091170137a72c1d54d641493c1f with
// a fix to have padding for numbers < 16
// get sixteen unsigned 8 bit random values
let u = window.crypto.getRandomValues(new Uint8Array(16));
// set the version bit to v4
u[6] = (u[6] & 0x0f) | 0x40;
@urmastalimaa
urmastalimaa / gist:bac1d0be881cf57808e7efe37438f5ee
Last active April 25, 2019 12:40
Transporter channel serializer :ets cache benchmark
defmodule Transporter.Test do
@cache_table_name :channel_serializer_cache
def run(payload, %{subscribers_count: subscribers_count, use_cache: use_cache}) do
if :ets.whereis(@cache_table_name) == :undefined do
init_cache()
end
delivery_key = {:node1@somehost, System.monotonic_time()}
@urmastalimaa
urmastalimaa / pwned_check.rb
Last active January 17, 2019 10:47
Have I been pwned check via a ruby script
# frozen_string_literal: true
# Requires ruby 2.1 or newer
#
# This script checks a single password or a list of passwords against
# pwnedpasswords HTTP API. The passwords are hashed and anonymized before
# sending them over the wire. Each password that has been pwned will be printed
# to standard out in clear text with the known pwnage count.
#
# Read more at https://haveibeenpwned.com/API/v2#PwnedPasswords
@urmastalimaa
urmastalimaa / repro.js
Last active August 3, 2017 13:08
Reproduce editing CSS in memory
document.body.innerHTML = '';
$(document.head).append("<link rel='stylesheet' type='text/css' href='https://mleibman.github.io/SlickGrid/slick.grid.css' />");
$(document.body).append("<script src='https://mleibman.github.io/SlickGrid/lib/jquery-1.7.min.js' /><script src='https://mleibman.github.io/SlickGrid/lib/jquery.event.drag-2.2.js' /><script src='https://mleibman.github.io/SlickGrid/slick.core.js' /><script src='https://mleibman.github.io/SlickGrid/slick.grid.js' /><div id='myGrid' style='width:600px;height:500px;' />");
var grid;
var columns = [
{id: "title", name: "Title", field: "title"},
{id: "duration", name: "Duration", field: "duration"},
{id: "%", name: "% Complete", field: "percentComplete"},
];
@urmastalimaa
urmastalimaa / EmbraceSimplicity2.js
Created April 29, 2016 09:59
Embrace Simplicity
// What is the actual meaning of this function?
const mapStateToProps = (state) => {
return {
words: state.remoteGame.words,
currentInput: state.remoteGame.currentInput,
pastInput: state.remoteGame.pastInput
}
}
@urmastalimaa
urmastalimaa / EmbraceSimplicity.js
Last active April 29, 2016 08:48
Embrace simplicity
// Given an initial state
const initialState = {
inputWord: null,
completedWords: [],
startTime: null,
words: [],
gameHasStarted: false,
highestWordsPerMinute: "0",
highestAccuracy: "0",
@urmastalimaa
urmastalimaa / zipHomework.js
Last active March 18, 2018 09:59
Script to zip a javascript project without node_modules
const Archiver = require('archiver'); // `yarn add --dev archiver` or `npm install --save-dev archiver`
const fs = require('fs');
const IGNORE_DIR_PATTERNS = [/node_modules/];
const IGNORE_FILE_PATTERNS = [];
const TARGET_FILE_NAME = 'homework.zip';
const matchesAnyPattern = (patterns, testString) => {
return patterns.some((pattern) => testString.match(pattern));
};
@urmastalimaa
urmastalimaa / gist:fa1b2cc29c3452278b28
Last active February 18, 2016 08:58
monadic_tracktor
require 'rubygems'
require 'deterministic'
include Deterministic::Prelude::Result
Operator = Class.new
Visitor = Class.new
fetch_operator = Proc.new {|request|
Operator.new
@urmastalimaa
urmastalimaa / identifying_and_debugging_n+1_queries.md
Last active August 29, 2015 14:24
How to identify and debug N+1 ActiveRecord queries.

Description

Unless you are fetching millions of rows,
the problem is most likely not in the query,
but in the amount of queries.

You are probably iterating over an entity and making many queries per each entity,
which kills performance (also known as the N+1 queries problem).

For example in the case of the engagement logs,
every engagement was iterated over and

@urmastalimaa
urmastalimaa / gist:e5b317780714f7bf86eb
Last active August 29, 2015 14:13
Git pre-push hook to protect master.
#!/bin/sh
# derived from https://gist.github.com/pixelhandler/5718585
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...