Skip to content

Instantly share code, notes, and snippets.

@mfekadu
mfekadu / app.py
Last active February 4, 2021 23:01 — forked from DmitryBe/app.py
SQLAlchemy quick start for MySQL
# http://bytefish.de/blog/first_steps_with_sqlalchemy/
# https://docs.sqlalchemy.org/en/13/
# https://www.sqlalchemy.org/library.html
# ^ if 1.3 is not current release
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine
from datetime import datetime, timedelta
from sqlalchemy import Table, Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.orm import relationship, backref
@jhonnymichel
jhonnymichel / gamedev-trigonometry.md
Last active August 18, 2024 10:45
Basic trigonometry for game development

Introduction

two distinct points (for example, a game object position and the mouse cursor position) in an area can always be two corners of a Right Triangle (Triângulo-retângulo in ptbr). A triangle has three sides: The Hypotenuse, the Adjacent and the Opposite.

The distance between two points in the X axis corresponds to the Adjacent side of a triangle, The distance between two points in the Y axis corresponds to the Opposite side of a triangle.

The Hypotenuse is the shortest distance between the two points.

This means we can use trigonometry to handle many interactions between objects when programming visual stuff.

Кодирование строк со словарём и обработка запроса без декодирования строк
===Мотивация
Пользователи часто используют тип данных %%String%% для хранения повторяющихся строковых значений. Мы всегда говорим, что это - антипаттерн и рекомендуем либо вручную писать вместо строк числовые идентификаторы, либо использовать %%Enum%%, либо использовать внешние словари. Но есть причины, по которым такой сценарий использования будет продолжать использоваться, и нам необходимо к нему адаптироваться.
Пример на данных Метрики Приложений:
(вырезано цензурой)
@jdarpinian
jdarpinian / executable.c
Last active May 30, 2024 19:42
Add one line to your C/C++ source to make it executable.
///$(which true);FLAGS="-g -Wall -Wextra --std=c17 -O1 -fsanitize=address,undefined";THIS_FILE="$(cd "$(dirname "$0")"; pwd -P)/$(basename "$0")";OUT_FILE="/tmp/build-cache/$THIS_FILE";mkdir -p "$(dirname "$OUT_FILE")";test "$THIS_FILE" -ot "$OUT_FILE" || $(which clang || which gcc) $FLAGS "$THIS_FILE" -o "$OUT_FILE" || exit $?;exec bash -c "exec -a \"$0\" \"$OUT_FILE\" $([ $# -eq 0 ] || printf ' "%s"' "$@")"
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
@arichardson
arichardson / CLion_Ninja.md
Last active January 25, 2024 15:23 — forked from nevkontakte/CLion_Ninja.md
Ninja support for CLion IDE

Ninja support for CLion IDE (working with newer versions of clion)

This script enables Ninja-powered builds in CLion IDE by wrapping around CMake, which it uses. See my blog post for details.

Disclaimer

This script is provided AS IS with no guarantees given or responsibilities taken by the author. This script relies on undocumented features of CLion IDE and may lead to instability of build and/or IDE. Use it on your own risk under WTFPL terms.

@juzim
juzim / packtpub_get_dl_links.js
Last active March 4, 2018 14:48
Create wget commands for all claimed books on packtpub
@donaldmunro
donaldmunro / gist:38841d72c65a1c32f2bf83a4a00a2c9a
Created March 5, 2017 13:26
Display/print a GLM mat or vec
#include <glm/gtx/string_cast.hpp>
..
..
glm::mat4 mat;
..
..
std::cout << glm::to_string(mat) << std::endl;
@meetingcpp
meetingcpp / jsonimport.hpp
Created February 26, 2016 20:20
Generic JSON Import - this code is accessing json via the json:: namespace and forwarding the types to various visitors to filter/import
template<class Import, class StringType = boost::string_ref>
struct JsonVisitor
{
JsonVisitor(Import& import,const boost::dynamic_bitset& filterresult):import(import),key(key),filterresult(filterresult){}
template<class Value>
bool operator()(const Value& v)const
{
import.processKeyValue(current_key,v);
return true;
}
@tristanfisher
tristanfisher / Ansible-Vault how-to.md
Last active June 11, 2024 13:23
A short tutorial on how to use Vault in your Ansible workflow. Ansible-vault allows you to more safely store sensitive information in a source code repository or on disk.

Working with ansible-vault


I've been using a lot of Ansible lately and while almost everything has been great, finding a clean way to implement ansible-vault wasn't immediately apparent.

What I decided on was the following: put your secret information into a vars file, reference that vars file from your task, and encrypt the whole vars file using ansible-vault encrypt.

Let's use an example: You're writing an Ansible role and want to encrypt the spoiler for the movie Aliens.

@Kein1945
Kein1945 / gist:9111512
Last active July 2, 2023 16:14
Стеммер Портера для русского языка на Python
# -*- coding: utf-8 -*-
# Портирован с Java по мотивам http://www.algorithmist.ru/2010/12/porter-stemmer-russian.html
import re
class Porter:
PERFECTIVEGROUND = re.compile(u"((ив|ивши|ившись|ыв|ывши|ывшись)|((?<=[ая])(в|вши|вшись)))$")
REFLEXIVE = re.compile(u"(с[яь])$")
ADJECTIVE = re.compile(u"(ее|ие|ые|ое|ими|ыми|ей|ий|ый|ой|ем|им|ым|ом|его|ого|ему|ому|их|ых|ую|юю|ая|яя|ою|ею)$")
PARTICIPLE = re.compile(u"((ивш|ывш|ующ)|((?<=[ая])(ем|нн|вш|ющ|щ)))$")
VERB = re.compile(u"((ила|ыла|ена|ейте|уйте|ите|или|ыли|ей|уй|ил|ыл|им|ым|ен|ило|ыло|ено|ят|ует|уют|ит|ыт|ены|ить|ыть|ишь|ую|ю)|((?<=[ая])(ла|на|ете|йте|ли|й|л|ем|н|ло|но|ет|ют|ны|ть|ешь|нно)))$")