Skip to content

Instantly share code, notes, and snippets.

View pilosus's full-sized avatar

Vitaly Samigullin pilosus

View GitHub Profile
@pilosus
pilosus / compress.clj
Last active November 23, 2024 12:30
String compression based on substitution of the sequences of repetitive chars with the char itself and, if the sequence is longer than 1 char, number of repetition
(ns compress
"Compress given string so that consecutive characters are grouped into
a character itself and number of repetitions if the count is more
than one:
(compress 'aaaBBccBDH')
'a3B2c2BDH'
(compress 'aaa')
'a3'
@pilosus
pilosus / rename_alembic_migrations.py
Created May 3, 2024 15:42
Python script to rename alembic migration files after `file_template` configuration option is changed from default one
"""
Copyright (c) 2024 Vitaly Samigullin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@pilosus
pilosus / calculate.md
Last active December 1, 2024 16:48
Count projects with GitHub link on clojure-toolbox.com website with babashka

$ bb toolbox.clj

{:total 1001, :github 970}

@pilosus
pilosus / schedule.py
Created February 23, 2022 10:49
Schedule for two working days in proper working hours
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
# working hours: 10:00 to 18:59
day_start = 0
day_end = 23
work_start = 10
work_end = 18
@pilosus
pilosus / parens.clj
Created October 3, 2021 13:20
Check if a string contains balanced parenthesis in Clojure
(def openning ["(" "[" "{"])
(def closing [")" "]" "}"])
(def parens (zipmap openning closing))
(defn parens-balanced?
[s]
(loop [input-string s
stack []]
(if (empty? input-string)
(empty? stack)

Keybase proof

I hereby claim:

  • I am pilosus on github.
  • I am pilosus (https://keybase.io/pilosus) on keybase.
  • I have a public key ASB_iFYud-BE_njrIsrogstPTQGd_qt15lJ9EpyO8ATWVAo

To claim this, I am signing this object:

@pilosus
pilosus / models.py
Created November 4, 2016 12:00
Comment SQLAlchemy model
class Comment(db.Model):
"""Comment is a message under a post.
Comment that has a parent treated as a reply. Comment with replies
(children) represents n-ary tree.
"""
__tablename__ = 'comments'
id = db.Column(db.Integer, primary_key=True)
parent_id = db.Column(db.Integer, db.ForeignKey('comments.id'))
@pilosus
pilosus / AnimalTest.java
Created October 3, 2016 12:51
Stepic Java Basics MOOC. Step 5.4.8 unit-test
package org.stepic.java.module5.animalSerialization;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by vitaly on 03/10/16.
*/
public class AnimalTest {
@pilosus
pilosus / Animal.java
Created October 3, 2016 12:49
Stepic Java Basics MOOC. Step 5.4.8
package org.stepic.java.module5.animalSerialization;
import java.io.Serializable;
import java.io.*;
import java.util.Objects;
/**
* Created by vitaly on 03/10/16.
*/
public class Animal implements Serializable {
@pilosus
pilosus / SerializationDemo.java
Created October 3, 2016 09:05
An exmple of serialization in Java
package org.stepic.java.module5.serializationDemo;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
/**
* Created by vitaly on 03/10/16.