Friday, September 30
Shadow

Month: August 2022

Python generator for public holidays in Poland

gist
from datetime import date, timedelta from dateutil import easter from dateutil.relativedelta import * def get_holidays(year=2010): """ Returns Polish hollidays dates (legally considered non-working days) """ easter_sunday = easter.easter(year) holidays = {'New Year': date(year,1,1), 'Trzech Kroli': date(year,1,6), 'Easter Sunday': easter_sunday, 'Easter Monday': easter_sunday + timedelta(days=1), 'Labor Day': date(year,5,1), 'Constitution Day': date(year,5,3), # 7th Sunday after Easter # (notice days+1 - this is 7th Sunday excluding Easter Sunday 'Pentecost Sunday': easter_sunday + relativedelta(days=+1, weekday=SU(+7)), # 9th Thursda...

its useless but its a start

gist
birth_year = input("Enter your birth year: ") age = 2022 - int(birth_year) needed_age = 20 required_years = 21 - int(age) def add(x, y): return x + y def subtract(x, y): return x - y def multiply(x, y): return x * y def divide(x, y): return x / y if age < 20: print("Access denied. You are " + str(age) + ", the required age is: 21 please try again in " + str(required_years) + " years.") elif age > 20: print("Welcome " + "your are " + str(age) + " years old, the required age is 21 Have a good" " rest of your " "day!") print("Select operation.") print("1.Add") print("2.Subtract"...

Hex grid triangle

gist
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>AZ kvíz</title> <style> /* https://css-tricks.com/hexagons-and-beyond-flexible-responsive-grid-patterns-sans-media-queries/ */ .main { display: flex; --rows: 7; --size: calc(100vh / var(--rows)); --margin: 4px; --float: calc(1.732 * var(--size) + 4 * var(--margin) - 1px); --max-width: calc(var(--rows) * (var(--size) + 2 * var(--margin))); } .container { font-size: 0; /*disable white space between inline block element */ max-width: var(--max-width); margin: 0 auto; } ...

cross-framework-web-components-2

gist
... @customElement('card-image') export class Card extends LitElement { @property({ type: Object }) card!: CardConfig; render() { return html` <li class="card"> <div class="img"> <img src="${this.card.image}" alt="${this.card.altText}" /> </div> <div class="text"> <h2> <a id="card-link" href="${this.card.link}" aria-describedby="desc-a-card" >${this.card.title}</a > </h2> <p>${this.card.text}</p> <span class="cta" aria-hidden="true" id="desc-a-card">${this.card.ctaText}</span> <small><a href="${this.card.textDescLink}">${this.card.textDesc}</a><...

Useful PostgreSQL Queries and Commands

gist
-- show running queries (pre 9.2) SELECT procpid, age(clock_timestamp(), query_start), usename, current_query FROM pg_stat_activity WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' ORDER BY query_start desc; -- show running queries (9.2) SELECT pid, age(clock_timestamp(), query_start), usename, query FROM pg_stat_activity WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' ORDER BY query_start desc; -- kill running query SELECT pg_cancel_backend(procpid); -- kill idle query SELECT pg_terminate_backend(procpid); -- vacuum command VACUUM (VERBOSE, ANALYZE); -- all database users select * from pg_stat_activity where current_query not like '<%'; -- all databases and their sizes select * from pg_user; -- all tables and their si...

For those following Ryan Michler’s Twelve-Week goals and need a Markdown version. I use mine in TheBrain Software

gist
The Four Quadrants, Goals, Due Apply due date Add GTD Tickler times tags Ensure Thought Type is Personal Project Set Energy Investment tag Goals Calibration X Connection X Condition x Contribution X Questions Why are these Twelve-Week objectives important to me? What will it look and feel like when I accomplish these objectives? What is the cost for not completing these objectives? What situations could arise that would keep me from accomplishing what I set out to do? How will I handle these when they arise? How will I celebrate the completion of my Twelve-Week objectives?

Preview Slow CPS in Ren’Py

gist
## Response to/Adapted from methanoliver https://gist.github.com/methanoliver/bbb026b2c6daeb9b7aae508314e30cfd ## and Lezalith: https://gist.github.com/Lezalith/f6ea469f10f10d21f53c2c5f592cd12f ## This is a version specifically geared towards display on the preferences screen. init -10 python: class PreviewSlowText(renpy.Displayable): """ A class to display a preview of the current CPS settings. Attributes: ----------- text : string The text to display for this displayable preview. properties : dict Optional keyword arguments that will be applied to the text to style it. """ def __init__(self, text, **properties): super(PreviewSlowText, self).__init__() # Stor...

Here we are using DbSet to use any class related to the database context in this way to create Base Repository

gist
using Microsoft.EntityFrameworkCore; using WebApiCustomers.Data; namespace WebApiCustomers.Repositories; public class BaseRepository<TEntity> : IRepository<TEntity> where TEntity : class { private readonly CustomerDemoDbContext _context; private readonly DbSet<TEntity> _dbset; public BaseRepository(CustomerDemoDbContext context) { _context = context; _dbset = _context.Set<TEntity>(); } public async Task AddAsync(TEntity entity) => await _dbset.AddAsync(entity); public async Task<IEnumerable<TEntity>> GetAllAsync() => await _dbset.ToListAsync(); public async Task<TEntity?> GetAsync(int? id) => await _dbset.FindAsync(id); public async Task DeleteAsync(int id) { var dataToDelete = await _dbset.FindAsyn...

Simple example of how BlockChain works.

gist
const SHA256 = require('crypto-js/sha256'); class Transaction { constructor(public from: string, public to: string, public amount: number) {} } const sampleTransaction1 = {from: "Mehmet", to: "D++", amount: 100}; const sampleTransaction2 = {from: "D++", to: "Mehmet", amount: 100}; class Block { public timestamp: number; public hash: string; constructor(public index: number, public data: object, public prevHash: string = "0000") { this.timestamp = Date.now(); this.hash = this.calculateHash(); } public calculateHash() { return SHA256(this.prevHash + this.timestamp + JSON.stringify(this.data)).toString(); } } class BlockChain { public chain: Block[]; constructor() { this.chain = [this.createGenesisBlock()]; ...