Skip to content

Instantly share code, notes, and snippets.

View Shtille's full-sized avatar

Vladimir Shtille

  • Moscow
View GitHub Profile
@Shtille
Shtille / pack_file.js
Created April 27, 2023 14:40
Inflates file content and encodes as base64
/**
* To use this module simply run:
* ~~~{.sh}
* node pack_file.js
* ~~~
*/
const fs = require('fs');
const zlib = require('zlib');
@Shtille
Shtille / build-so.sh
Created April 7, 2022 15:45
Shell script to build shared library for Android via CMake build system
#!/bin/zsh
android_abi=armeabi-v7a
android_platform=android-19
path_to_cmakelists=~/Documents/dev/src/smartplatform-CMake
path_to_generated=~/Documents/dev/src/build
path_to_ndk=~/Library/Android/sdk/ndk/24.0.8215888
path_to_ninja=/usr/local/bin/ninja
@Shtille
Shtille / spin_perf.cpp
Created February 11, 2022 10:48
Custom spinlock vs pthread one speed comparison
#include <cstdlib>
#include <cstdio>
#include <thread>
#include <string>
#include <chrono>
#include <atomic>
#include <pthread.h>
class ScopeTimer {
@Shtille
Shtille / lru-cache.js
Created August 10, 2021 00:40
Simple LRU cache on pure JavaScript
/**
* Copyright (c) 2021 Vladimir Sviridov.
* Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT).
*
* Module defines LRU cache class.
*/
/**
* Defines LRU cache
*
@Shtille
Shtille / custom_app_bar.dart
Created October 29, 2020 13:19
Custom app bar
import 'package:flutter/material.dart';
/// Custom appbar with custom paddings and height
class MyCustomAppBar extends StatelessWidget implements PreferredSizeWidget {
final double _height;
final Widget Function(BuildContext context) _builder;
/// Builds custom app bar with [height] and [builder].
const MyCustomAppBar({
Key key,
@Shtille
Shtille / completer_eample.dart
Created October 9, 2020 17:06
Completer usage example
import 'dart:async';
Future<String> someFutureResult(){
final c = new Completer<String>();
// complete will be called in 3 seconds by the timer.
new Timer(Duration(seconds: 3), () => c.complete("you should see me second"));
return c.future;
}
main(){
@Shtille
Shtille / downloadCsv.js
Last active June 9, 2020 14:05
Download object array as CSV file
getObjectRows : function(array) {
if (!Array.isArray(array))
return new Array();
if (array.length == 0)
return new Array();
var rows = new Array();
var namesRow = new Array();
var obj = array[0];
for (var prop in obj) {
if (obj.hasOwnProperty(prop) && typeof obj[prop] !== "function" && typeof obj[prop] !== "object") {
@Shtille
Shtille / download.js
Created June 2, 2020 22:16
Download object as JSON
function download(content, fileName, contentType) {
var a = document.createElement("a");
var file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
URL.revokeObjectURL(a.href);
}
// Usage
var jsonObject = {
@Shtille
Shtille / main.js
Created May 19, 2020 19:55
Sending analytics information to web server on exit
window.addEventListener('beforeunload', function (e) {
sendAnalyticsData();
});
function sendAnalyticsData() {
if (navigator && navigator.sendBeacon) {
navigator.sendBeacon(url);
} else {
$.ajax({
type: 'POST',
@Shtille
Shtille / actionPromise.js
Last active April 20, 2020 13:49
Promise class for JavaScript.
/**
* Module describes classes ActionPromise and ActionPromiseList.
* Exceptionally useful when your executed code has asynchronous dependencies.
* Keeps the same execution order as promises have been added despite the server response.
*
* Here's an example of code:
* @code{.js}
* needAddress = true;
* needGeometry = true;
* requestAddress(function(){