Skip to content

Instantly share code, notes, and snippets.

View marsgpl's full-sized avatar
🧬
AI

Iurii Belobeev marsgpl

🧬
AI
View GitHub Profile
@marsgpl
marsgpl / openUrl.dart
Last active May 11, 2020 13:42
Flutter open url
import 'package:url_launcher/url_launcher.dart';
Future<bool> openUrl(String url) async {
if (url == null || url.trim().length == 0) {
return false;
}
url = Uri.encodeFull(url.trim());
if (!url.contains('://')) {
const fetch = require("node-fetch")
const fetchAll = async function(urls, max=3) {
const results = Array(urls.length)
const workers = Array(max)
const index = {value:0}
for (let i=0; i<max; ++i) {
workers.push(fetchAll.worker(urls, results, index))
}
const rotateWords = function(arr) {
rotateWords.reverse(arr, 0, arr.length-1)
let firstSpaceIndex = arr.indexOf(" ")
let secondSpaceIndex = arr.indexOf(" ", firstSpaceIndex + 1)
rotateWords.reverse(arr, 0, firstSpaceIndex - 1)
rotateWords.reverse(arr, firstSpaceIndex + 1, secondSpaceIndex - 1)
rotateWords.reverse(arr, secondSpaceIndex + 1, arr.length - 1)
// ABAZDC, BACBAD => ABAD
// AGGTAB, GXTXAYB => GTAB
// aaaa, aa => aa
const getLongestSubseq = function(s1, s2) {
let longest = null
for ( let s1from=0; s1from<s1.length; ++s1from ) {
let current = []
let s1i = s1from, s2i = 0
const genBrackets = function(n) {
const result = []
if ( n > 0 ) {
genBrackets.add(n, 0, "", result)
}
return result.join(" ")
}
var moneyTypes = [5000, 1000, 500, 100, 50, 30]
var lims = {
5000: 4,
1000: 5,
500: 2,
100: 5,
50: 100,
30: 23
}
const getAnagrams = function(...args) {
const anagrams = []
const candidates = {}
for ( let word of args ) {
let wordNorm = getAnagrams.normalize(word)
if ( candidates[wordNorm] ) {
anagrams.push([word, candidates[wordNorm]])
const check = function(seq) {
let opened = []
for ( let char of seq ) {
if ( check.openers[char] ) {
opened.push(char)
} else { // closers
if ( opened.length==0 || opened[opened.length-1] !== check.closers[char] ) {
return false
} else {
const getPrimes = function(n) {
const result = []
for ( let i=2;i<=n;++i ) {
if ( getPrimes.isPrime(i) ) {
result.push(i)
}
}
return result
const Stack = function(data = []) {
this.data = data
}
Stack.prototype.push = function(value) {
this.data.push(value)
}
Stack.prototype.pop = function() {
return this.data.pop()