Skip to content

Instantly share code, notes, and snippets.

@Priler
Priler / gist:b2d4c9d97231f3ec9bb9993786f4ff57
Created June 22, 2016 07:18
.format() for JavaScript, as in Python
// First, checks if it isn't implemented yet.
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
86937 isset
43159 echo
31697 empty
29252 substr
26146 count
24248 is_array
22572 strlen
19365 sprintf
18090 unset
16584 str_replace
import random
# используемые символы
chars = 'abcdefghyjklmnopqrstuvwxyz'
chars += chars.upper()
nums = str(1234567890)
chars += nums
special_chars = '!@#$%^&*()_+-'
chars += special_chars
@Priler
Priler / youtube_dl_download.py
Created July 22, 2021 09:45
Video download from YouTube with youtube-dl
from __future__ import unicode_literals
import youtube_dl
def progress_hook(d):
if(d['status'] == "downloading"):
print(f'{d["_speed_str"]} ({d["_percent_str"]})')
else:
print("Готово!")
ydl_opts = {
@Priler
Priler / weekday.py
Created July 23, 2021 09:03
Python get weekday (with calendar module, + localized)
from datetime import date
import calendar
import locale
locale.setlocale(locale.LC_ALL, 'ru_RU')
today = date.today()
print("Сегодня {}й день недели, {}!".format(
today.weekday(),
calendar.day_name[today.weekday()]))
@Priler
Priler / cv2_face_detection.py
Last active July 20, 2022 10:22
Face detection using Python OpenCV2
import cv2
import sys
imgPath = input("Введите путь к картинке:")
faceCascade = cv2.CascadeClassifier(
cv2.data.haarcascades+'haarcascade_frontalface_default.xml')
img = cv2.imread(imgPath)
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
@Priler
Priler / CubeController.cs
Last active November 15, 2021 12:45
CubeController.cs
using UnityEditor;
using UnityEngine;
using DG.Tweening;
/// <summary>
/// Attribute to select a single layer.
/// </summary>
public class LayerAttribute : PropertyAttribute
{}
@Priler
Priler / GD3DCameraFollow.cs
Created July 30, 2021 09:01
Geomtry Dash camera follow
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
[ExecuteInEditMode]
public class GD3DCameraFollow : MonoBehaviour
{
[SerializeField]
private Transform playerTransform;
@Priler
Priler / heapq_vs_sort.py
Created July 31, 2021 09:26
Simple performance measure test for Heapq.nlargest vs sort() in Python
def naive_find_top_k(values, k=20):
values.sort(reverse=True)
return values[:k]
import heapq
def heap_find_top_k(values, k=20):
return heapq.nlargest(k, values)
import random
@Priler
Priler / chat_server.cpp
Last active December 5, 2022 11:22
??? :3
/* Лол, код из архива - файл датируется 2017 годом.
Написан был после недели изучения C++.
Реализует серверную часть чата на клиенте.
Код не полный, писался на скорую руку - так сказать proof of concept.
О, и да - семафоры это круто :3 */
#include <iostream>
#include <string>
#include <stdio.h>
#include <cstring>
#include <stdlib.h>