Skip to content

Instantly share code, notes, and snippets.

View karlkori's full-sized avatar
:octocat:

Serhii Drahunov karlkori

:octocat:
View GitHub Profile
@karlkori
karlkori / saveTextAsFile.js
Created March 18, 2023 13:05
saveTextAsFile
function saveTextAsFile(textToWrite, fileNameToSaveAs, fileType) {
let textFileAsBlob = new Blob([textToWrite], { type: fileType });
let downloadLink = document.createElement('a');
downloadLink.download = fileNameToSaveAs;
downloadLink.innerHTML = 'Download File';
if (window.webkitURL != null) {
downloadLink.href = window.webkitURL.createObjectURL(
textFileAsBlob
);
@karlkori
karlkori / gist:dc08ccfbd9c8827525776c585cf57a10
Created October 19, 2018 07:31
remove unused docker components
#!/bin/bash
# удаление завершенных контейнеров:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# удаление неиспользуемых контейнеров:
yes | docker container prune
# удаление не используемых образов:
yes | docker image prune
# удаление не используемых томов:
yes | docker volume prune
@karlkori
karlkori / nginx.conf
Created June 18, 2017 06:32
nginx tls configuration example
server {
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
@karlkori
karlkori / deploy.sh
Created April 12, 2017 12:59
CI script for AWS ECS
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
# change work directory
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$parent_path"
@karlkori
karlkori / two directions constant
Created September 30, 2016 14:28
two directions constant
const Role = new Proxy({
ADMIN: 1,
USER: 2,
GUEST: 3
}, {
get(target, key) {
return isNaN(key) ? target[key] : _.findKey(target, val => val == key);
}
});
@karlkori
karlkori / angular-production
Created May 10, 2016 14:58
disable debug info for increase perfomance in production
myApp.config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
}]);
@karlkori
karlkori / README.md
Created January 25, 2016 15:00 — forked from magnetikonline/README.md
Shell redirection cheatsheet.
@karlkori
karlkori / correct-terminate-nodejs-process.js
Last active January 17, 2016 11:56
correct terminate node.js process
var server = require('./server');
var shuttingdown = false;
['SIGINT', 'SIGTERM'].forEach(function(signal) {
if (! shuttingdown) {
shuttingdown = true;
server.close();
// terminate process after 30 seconds anyway
@karlkori
karlkori / optional-arguments.js
Last active November 26, 2015 16:23 — forked from klovadis/gist:2549131
How to use optional arguments in node.js
// example function where arguments 2 and 3 are optional
function example( err, optionalA, optionalB, callback ) {
// retrieve arguments as array
var args = [];
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
// first argument is the error object
@karlkori
karlkori / angular-and-other-libs.js
Last active November 12, 2015 10:14
How use js libs in Angular
/* include js lib (lodash) before angular! */
'use strict';
angular
.module('app', [])
.factory('_', ['$window', function($window) {
return $window._;
}])