Skip to content

Instantly share code, notes, and snippets.

View vladislav805's full-sized avatar

Vladislav Veluga vladislav805

View GitHub Profile
@vladislav805
vladislav805 / pluralize.js
Last active June 14, 2020 20:52
Pluralize: 1 item, 2 items, 5 items / 1 элемент, 2 элемента, 5 элементов
export const pluralize = (number, cases) => {
number = Math.abs(number);
return cases[number % 100 > 4 && number % 100 < 20 ? 2 : [2, 0, 1, 1, 1, 2][number % 10 < 5 ? number % 10 : 5]];
};
@vladislav805
vladislav805 / toTimeFormat.js
Created December 3, 2016 20:24
Duration in seconds to "h:mm:ss" format
Number.prototype.toTimeFormat = function() {
var d = [Math.floor(this / 60 % 60), Math.floor(this % 60)],
h = Math.floor(this / 60 / 60 % 60);
d = d.map(function(n) {return n >= 10 ? n : "0" + n});
h && d.unshift(h);
return d.join(":");
};
// using
var duration = 12345;
Number.prototype.toData = function() {
if (this <= 0) {
return "0 bytes";
};
var n;
for (var i = 5; i >= 0; --i) {
n = Math.round(this / Math.pow(1024, i) * 10) / 10;
if (n >= 1) {
return n + " " + ["b", "KB", "MB", "GB", "TB"][i]);
@vladislav805
vladislav805 / reArrangeFiles.php
Last active January 3, 2017 17:15
Rearrange $_FILES from { name = [1, 2, 3], size = [1, 2, 3], ... } to [ { name = 1, size = 1 }, { name = 2, size = 2 }, ... ]
<?
function reArrayFiles(&$files) {
$result = [];
$keys = array_keys($files);
for ($i = 0, $l = sizeof($files["name"]); $i < $l; $i++) {
foreach ($keys as $key) {
$result[$i][$key] = $files[$key][$i];
};
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
public class Gauss {
public static void swapRows(double[][] a, double[] b, int i, int j) {
double[] row = a[i];
#!/bin/bash
TOKEN="..."
echo "Enter URL to video (in format OID_VID)"
read vkUrl
#vkUrl="203384908_456239021"
hls=$(wget -qO - "https://api.vk.com/method/video.get?videos=$vkUrl&access_token=$TOKEN&v=5.56" | grep -iowE "hls\"\:\"http[^\"]*\"" | grep -iowE "http.[^\"]*" | sed 's!\\/!/!g')

ffmpeg tips

Examples

Download HLS to file

ffmpeg -i input.m3u8 -c copy -bsf:a aac_adtstoasc output.mp4
@vladislav805
vladislav805 / HEAD-detached-fix.sh
Created October 2, 2019 12:50
HEAD detached fix
TARGET_BRANCH="master"
TEMPORARY_BRANCH="temp"
git branch "$TEMPORARY_BRANCH"
git checkout "$TEMPORARY_BRANCH"
git branch -f "$TARGET_BRANCH" "$TEMPORARY_BRANCH"
git checkout "$TARGET_BRANCH"
git branch -d "$TEMPORARY_BRANCH"

Pacman

-S: Installing wiki

Install package

# pacman -S package

-Sy, -Syy

Sync (analog apt update). Double y - force sync.

-Su

@vladislav805
vladislav805 / arch.md
Last active November 4, 2021 08:54
Cheatsheet by install and using Arch Linux

Arch Linux

Install Arch Linux with EFI

  1. Download ISO from official site
  2. Burn the ISO to a USB flash using Rufus with Partition Scheme = GPT, Target = EFI (non CSM).
  3. Boot to BIOS/UEFI, disable CSM.
  4. Boot from USB flash with EFI.
  5. Check connection with Internet

ping -c 2 google.com