Skip to content

Instantly share code, notes, and snippets.

View shanginn's full-sized avatar
🔨
building stuff

Николай Шангин shanginn

🔨
building stuff
View GitHub Profile
@shanginn
shanginn / # smolid.md
Last active October 22, 2024 07:09
Fast unique smol ID generator

Smaller than UUID and copy-paste friendly.

JIN5gNQEwht8999c4xZx9
88AFNNkR1RJI1gs8BBwxV
c54wMAUAR4wkFs9dN9Jts

Inspired by Nano ID

const { Telegraf } = require('telegraf')
const bot = new Telegraf('TOKEN')
// Create an object to store the user's information
const userData = {}
// Set up a command to start the conversation with the user
bot.command('start', ctx => {
// Define the userData object for the current user
userData[ctx.from.id] = {}
@shanginn
shanginn / task.awk
Created February 18, 2018 13:41
Yandex SHKIB task 5. # Usage: ./task.awk shkib.csv > result.txt
#!/usr/bin/gawk -f
BEGIN {
FS = ","
PROCINFO["sorted_in"] = "@val_num_desc"
}
{
if ($2 != "") {
most_requests[$2]++
@shanginn
shanginn / install_sublime_text.sh
Last active February 21, 2017 22:14 — forked from simonewebdesign/install_sublime_text.sh
Install Sublime Text 3 on Linux via POSIX shell script - http://simonewebdesign.it/install-sublime-text-3-on-linux/
#!/bin/sh
# Sublime Text 3 install with Package Control (last update: 25 September 2016)
#
# No need to download this script, just run it on your terminal:
#
# $ curl -L git.io/sublimetext | sh
# Detect the architecture
@shanginn
shanginn / README.md
Last active August 8, 2024 13:40
Get available relationships trait for Eloquent model (Laravel 5.*)

GetRelationships Trait

This trait will allow you to get defined relationships on the model. I wish Laravel have a way to get this without any additions(except for trait), but there is no way.

Here we have 2 versions of the trait: for PHP7 and for PHP5.

Both method uses Reflections to collect information about the model.

PHP7

With PHP7 version you'll only need to add return class for the relationship method like this:

@shanginn
shanginn / BootstrapLastTab.js
Created January 13, 2016 08:23
Make Bootstrap 3 remember which tab they were on. Works only with one set of tabs.
var $tabLinks = $('a[data-toggle="tab"]');
if($tabLinks.length) {
var lastTab = localStorage.getItem('lastTab');
$tabLinks.on('click', function (e) {
//save the latest tab; use cookies if you like 'em better:
localStorage.setItem('lastTab', $(e.target).attr('href'));
});
//go to the latest tab, if it exists:
var $target = lastTab ? $('a[href="' + lastTab + '"]') : $tabLinks.first();
$target.tab('show');