Skip to content

Instantly share code, notes, and snippets.

@romamik
romamik / leetcode3109.py
Created January 4, 2026 16:22
leetcode 3109 solution
"""
This is the solution for: https://leetcode.com/problems/find-the-index-of-permutation/description/
It is not available without premium though
Given an array perm of length n which is a permutation of [1, 2, ..., n], return the index of perm in the lexicographically sorted array of all of the permutations of [1, 2, ..., n].
Since the answer may be very large, return it modulo 10^9 + 7.
Example 1:
#include <string>
#include <iostream>
#include <fstream>
#include <map>
#include <locale>
#include <vector>
#include <algorithm>
void countWords(std::ifstream &in, std::map<std::string, int> &result) {
std::string word;
@romamik
romamik / Main.hx
Created February 15, 2017 14:17
haxe null safety example
package;
import haxe.macro.Expr;
class Bar {
public var foo:Foo = null;
public function new() {}
}
class Foo {
public function new() {}
@romamik
romamik / KhaImageFromEncodedBytes.hx
Created January 11, 2017 08:29
Create kha image from encoded (png, jpg, etc...) bytes
package;
import haxe.io.Bytes;
import kha.Image;
#if sys_kore
@:cppFileCode('
#include <Kore/Graphics/stb_image.h>
#ifndef INCLUDED_kha_graphics4_TextureFormat
#include <kha/graphics4/TextureFormat.h>
@romamik
romamik / unzip.hx
Created November 8, 2016 15:10
haxe read zip file in js and flash and sys targets
//add this to html to use in js: <script src="pako_inflate.min.js"></script>
//also put this file near html file: https://github.com/nodeca/pako/blob/master/dist/pako_inflate.min.js
function unzipEntry(entry:haxe.zip.Entry) {
#if flash
if (entry.compressed) {
var data = entry.data.getData();
data.inflate();
entry.data = Bytes.ofData(data);
}