Skip to content

Instantly share code, notes, and snippets.

View alekstar79's full-sized avatar
🎯
Focusing

Aleksey Tarasenko alekstar79

🎯
Focusing
View GitHub Profile
@alekstar79
alekstar79 / weblancer.py
Created March 8, 2016 14:38 — forked from mr-linch/weblancer.py
Исходный код для урока (https://youtu.be/KPXPr-KS-qk)
#!/usr/bin/env python3
import csv
import urllib.request
from bs4 import BeautifulSoup
BASE_URL = 'http://www.weblancer.net/projects/'
@alekstar79
alekstar79 / draggable.html
Last active May 24, 2024 16:57
Draggable
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Draggable</title>
<style>
.draggable {
position: absolute;
@alekstar79
alekstar79 / init.coffee
Last active May 24, 2024 17:34 — forked from psylone/init.coffee
Atom sync settings [archive]
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@alekstar79
alekstar79 / Install PyQt5 on Ubuntu with python3 .md
Created January 16, 2021 18:28 — forked from r00tdaemon/Install PyQt5 on Ubuntu with python3 .md
Install PyQt5 on Ubuntu with python3. Steps to set up PyQt5 (ubuntu). With python code generation

Installation

pip3 install --user pyqt5  
sudo apt-get install python3-pyqt5  
sudo apt-get install pyqt5-dev-tools
sudo apt-get install qttools5-dev-tools

Configuring to run from terminal

@alekstar79
alekstar79 / one-line-utils.js
Created February 4, 2023 07:59
One-line JavaScript functions
// Immutable Shuffle
const shuffleImmutable = (arr) => arr.slice().sort(() => Math.random() - 0.5)
// Random number in range
const randomInRange = (from, to) => Math.floor(from + Math.random() * (to - from + 1))
// Array with unique items
const uniqueItems = (arr) => [...new Set(arr)]
// Uppercase firs letter
@alekstar79
alekstar79 / convert.php
Created February 4, 2023 09:18
Converting images to WebP in PHP
function convertToWebp(string $src, int $quality = 100): string
{
$dir = pathinfo($src, PATHINFO_DIRNAME);
$name = pathinfo($src, PATHINFO_FILENAME);
$ext = pathinfo($src, PATHINFO_EXTENSION);
$dest = "$dir/{$name}_$ext.webp";
$is_alpha = false;
switch (mime_content_type($src)) {
@alekstar79
alekstar79 / ab2str.js
Created April 24, 2023 10:43
Convert ArrayBuffer to String
export function ab2str(buf)
{
return String.fromCharCode.apply(null, new Uint16Array(buf))
}
@alekstar79
alekstar79 / str2ab.js
Created April 24, 2023 10:46
Convert String to ArrayBuffer
export function str2ab(str)
{
let buf = new ArrayBuffer(str.length * 2) // 2 bytes for each char
let bufView = new Uint16Array(buf)
for (let i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i)
}
return buf
@alekstar79
alekstar79 / async-array.js
Last active May 24, 2024 16:19
Async array
export class AsyncArray extends Array
{
[Symbol.asyncIterator]()
{
let i = 0
return {
next: () => new Promise(resolve => {
setTimeout(() => resolve({ value: this[i], done: i++ === this.length }))
})
@alekstar79
alekstar79 / binary.js
Last active May 24, 2024 16:23
Binary Search
Object.defineProperty(Array.prototype, 'binarySearch', {
value(target, comparator) {
let l = 0,
h = this.length - 1,
m, comparison
/* default comparison method if one was not provided */
comparator = comparator || function(a, b) {
return (a < b ? -1 : (a > b ? 1 : 0))
}