Skip to content

Instantly share code, notes, and snippets.

View archangel-irk's full-sized avatar
:octocat:

Konstantin Melnikov archangel-irk

:octocat:
View GitHub Profile
@archangel-irk
archangel-irk / export-notes.applescript
Created August 7, 2020 21:30 — forked from kyoh86/export-notes.applescript
Export notes from Note.app to PDF files.
-- 対象のフォルダの一番上を選択している状態から始める
set targetFolder to "aaa"
tell application "Notes"
activate
repeat with theFolder in every folder
if name of theFolder = targetFolder then
repeat with theNote in every note of theFolder
tell application "System Events"
key code 126
@archangel-irk
archangel-irk / gist:d59801d1f25f23913c28efd5070005db
Created September 3, 2019 06:21 — forked from stereokai/gist:36dc0095b9d24ce93b045e2ddc60d7a0
CSS rounded corners with gradient border
.rounded-corners-gradient-borders {
width: 300px;
height: 80px;
border: double 4px transparent;
border-radius: 80px;
background-image: linear-gradient(white, white), radial-gradient(circle at top left, #f00,#3020ff);
background-origin: border-box;
background-clip: content-box, border-box;
}
@archangel-irk
archangel-irk / useVisibilityState.ts
Created August 12, 2019 06:08
React Hook - Page Visibility API (tab document visible)
import { useEffect, useState } from 'react';
// Spec
// https://www.w3.org/TR/page-visibility-2/
// MDN
// https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
// https://developers.google.com/web/updates/2017/03/background_tabs
// Generate data
const k = 1 * 1000;
let gen = () => {
return Array.from({length: k}, () => Math.floor(Math.random() * k));
};
let a = gen();
// simple "hungry" solution
let denominations = [1, 7, 9];
function withdraw(amount) {
let remain = amount;
let result = [];
const denominationsSorted = denominations.sort((a, b) => b - a);
denominationsSorted.forEach((denomination) => {
let count = Math.floor(remain / denomination);
/*
-----------------------
Example:
-----------------------
Round 1
Player1 hits Player2 with 5 dmg
Player2 hits Player3 with 10 dmg
Player3 has died
Player4 hits Player1 with 4 dmg
// Complexity for getBondsData - 3n
// Memory - ?
class BondsCache {
constructor() {
this.data = new Map();
}
getId(date, isin) {
return `${date}_${isin}`;
// Float To Percent
// Complexity - 2n
// Memory - ?
// Input limit - 6e6 (6_000_000) elements
function floatToPercent(array) {
const total = array.reduce((acc, curr) => acc + parseFloat(curr), 0);
return array.map(value => {
return (parseFloat(value) / total * 100).toFixed(3);
});
@archangel-irk
archangel-irk / requiredParam.js
Created March 20, 2018 02:08
Required Parameters
function requiredParam (param) {
const requiredParamError = new Error(
`Required parameter, "${param}" is missing.`
);
// preserve original stack trace
if (typeof Error.captureStackTrace === ‘function’) {
Error.captureStackTrace(
requiredParamError,
requiredParam,
);
@archangel-irk
archangel-irk / loadScript.js
Last active January 3, 2018 12:33
loadScript (Promise)
function loadScript(src) {
return new Promise(function(resolve, reject) {
const script = document.createElement('script');
script.src = src;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
}