Skip to content

Instantly share code, notes, and snippets.

View nikitalarionov's full-sized avatar
🏠
Working from home

sphere89 nikitalarionov

🏠
Working from home
View GitHub Profile
@nikitalarionov
nikitalarionov / PostController.cs
Created January 12, 2023 14:48
Example Post Controller
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MySite.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
@nikitalarionov
nikitalarionov / my.py
Created May 5, 2021 00:03
convert ip to num
def iptoint(ip):
h=list(map(int,ip.split(".")))
return (h[0]<<24)+(h[1]<<16)+(h[2]<<8)+(h[3]<<0)
def inttoip(ip):
return ".".join(map(str,[((ip>>24)&0xff),((ip>>16)&0xff),((ip>>8)&0xff),((ip>>0)&0xff)]))
iptoint("8.8.8.8") # 134744072
inttoip(134744072) # 8.8.8.8
@nikitalarionov
nikitalarionov / edit_command.js
Last active June 27, 2019 16:08
Latest ckEditor DailyNotePlugin
import Command from '@ckeditor/ckeditor5-core/src/command';
export default class EditDailyNoteCommand extends Command {
execute() {
const editor = this.editor;
const model = editor.model;
const doc = model.document;
const selection = doc.selection;
const selectedElement = selection.getSelectedElement();
@nikitalarionov
nikitalarionov / plugin.js
Last active June 26, 2019 15:05
Note plugin example
// Example of data provided in ckEditor
// DATA = '`some text text text and: .... <div class="article-note js-tooltip">листовки<span class="article-note__tooltip"><span class="article-note__body js-tooltip-body" data-referal=""><img src="https://img03.rl0.ru/afisha/290x-/daily.afisha.ru/uploads/images/9/b5/9b50660636a19bb09f4314aa920cda1d.jpg" class="article-note__img js-article-note-img"></span></span></div>`;'
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import Widget from '@ckeditor/ckeditor5-widget/src/widget';
import CKEditorInspector from '@ckeditor/ckeditor5-inspector';
import {toWidget, toWidgetEditable, viewToModelPositionOutsideModelElement} from "@ckeditor/ckeditor5-widget/src/utils";
const baseEditingCls = 'dailynote';
@nikitalarionov
nikitalarionov / commandline.txt
Created March 11, 2019 21:05 — forked from sandervm/commandline.txt
Generate Django secret key commandline
$ python -c 'import random; print "".join([random.choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'
@nikitalarionov
nikitalarionov / dowirak.js
Last active February 15, 2019 15:07
DGTF Ch04 Exercises
const compose = (f, g) => x => f(g(x)); // Receives functions
const join = x => {
return y => {
if (typeof y === 'string') {
y = y.split();
}
return y.join(x);
}
}
@nikitalarionov
nikitalarionov / rotate_array_left.cpp
Created January 26, 2019 19:05
Rotate array to left by number of positions
// array_rotate.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
#include "pch.h"
#include <iostream>
using namespace std;
void left(int a[], unsigned N) {
@nikitalarionov
nikitalarionov / component.ts
Last active January 22, 2019 07:46
Authors code elegance example for review
class AuthorsComponent implements OnInit, OnDestroy {
authorsForm: FormGroup;
authorsFormArray: FormArray;
getAuthorFormField(person?: EntryAuthorRoleViewModel, mainAuthorId?: number) {
return this.fb.group({
name: new FormControl(person.author || '', Validators.required),
role: new FormControl(person.authorRole || '', Validators.required),
isMain: new FormControl(mainAuthorId === person.authorId || false, Validators.required)
@nikitalarionov
nikitalarionov / docker-compose.yml
Created May 2, 2018 18:50
postgre docker-compose example
services:
web:
restart: "no"
command: "echo 'web disabled'"
backup:
restart: "no"
command: >
bash -c "while ! nc -w 1 -z db 5432; do sleep 0.1; echo 'waiting for db...'; done;
sleep 2 &&
@nikitalarionov
nikitalarionov / pips.sh
Created May 1, 2018 14:00
Shell script to install pip dependencies
pips() {
local pkg=$1
if [ -z "$1" ]; then
echo "usage: pips <pkg name>"
return 1
fi
local _ins="pip install $pkg"
eval $_ins