Skip to content

Instantly share code, notes, and snippets.

View nikolay-kapustin's full-sized avatar
🖖

Nikolay Kapustin nikolay-kapustin

🖖
View GitHub Profile
@nikolay-kapustin
nikolay-kapustin / linear-gradient-to-UIKit.swift
Created April 9, 2020 11:42
CSS func linear-gradient() to UIKit CGGradientLayer coordinate space conversion
//: # CSS linear-gradient to UIKit coordinate space conversion
import UIKit
import PlaygroundSupport
//handy radians
func radian(degree:Double) -> Double { return degree * Double.pi / 180 }
func radian(degree:CGFloat) -> CGFloat { return degree * CGFloat(Double.pi / 180) }
func gradientPoints(size:CGSize, cssAngle:CGFloat) -> (start:CGPoint, end:CGPoint) {
@nikolay-kapustin
nikolay-kapustin / INN.swift
Last active March 25, 2020 12:53
Проверка ИНН на валидность. Алгоритм на Swift. #swift #inn #tin
class INNTests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
func testInn() {
func checkInn(_ inn:String) -> Bool {
let len = inn.count
@nikolay-kapustin
nikolay-kapustin / gist:5dd00626a5c1dab349224cec1b266cc1
Last active December 13, 2019 11:03
Vacations dates generator
<script>function%20r(e,t){return%20e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e}const%20m=r(7,10),nextY=(new%20Date).getFullYear()+1,d=r(1,28),options={year:"numeric",month:"long",day:"numeric"},firstPeriod=[new%20Date(nextY,m,d),new%20Date(nextY,m,d+14)].map(e=>e.toLocaleDateString("ru-RU",options)).join("%20-%20"),m2=r(2,6),d2=r(1,28),secondPeriod=[new%20Date(nextY,m2,d2),new%20Date(nextY,m2,d2+14)].map(e=>e.toLocaleDateString("ru-RU",options)).join("%20-%20");document.writeln(`${firstPeriod}<br>${secondPeriod}`);</script>
@nikolay-kapustin
nikolay-kapustin / script.gs
Created March 7, 2017 16:13
Google Apps Script for parsing entire gmail messages and save it into google spreadsheet
// Google may setup some restrictions for a massive requests per seconds.
// So you need planning to run script multiple times
var SEARCH_QUERY = '!label:Parsed_by_Script';
// The Main func - entry point
function gmailExportToSpreadsheet(){
// we
for (var index = 0; index <= 2000; index += 100){
parseEmailMessages(index);
Logger.log("Parsed next %s messages.", index);
@nikolay-kapustin
nikolay-kapustin / eth0_fix.sh
Created February 12, 2017 21:47
Raspberry Pi 3: Resolve eth0 interface naming issue
#!/bin/bash
# This script fix issue for unexpected not appearing the eth0 interface on the Raspberry Pi 3.
# The script is fixing the name of ethernet interface to 'eth0' persistently.
cd /etc/udev/rules.d/
touch 70-persistent-net.rules
echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="smsc95xx", ATTR{address}=="*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"' >> 70-persistent-net.rules