Skip to content

Instantly share code, notes, and snippets.

@abdusco
abdusco / cloudflaredns.py
Created February 20, 2021 10:03
Create Cloudflare DNS records with Python
import logging
from os import getenv
import httpx
logging.basicConfig(level=logging.DEBUG)
# go to https://dash.cloudflare.com/profile/api-tokens
# and create a token with Zone.DNS permissions
CLOUDFLARE_TOKEN = getenv('CLOUDFLARE_TOKEN')
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
namespace LinqDemo.Cli
{
class Person
{
public string Name { get; set; }
@abdusco
abdusco / DbContextBase.cs
Created April 13, 2020 08:51
c# soft delete
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Scratch.Core.Shared;
namespace Scratch.Infrastructure.Data
{
public class DbContextBase : DbContext
@abdusco
abdusco / requirements.txt
Last active February 1, 2020 19:38
Convert TTML to SRT
bs4
lxml

You can use re module together with string manipulation to extract the dates easily

import requests
import re
import json

if __name__ == "__main__":
    texts = [
        'en los dias 3,06,8 ,9, 15 y 29 de diciembre de 2018.Por c',
@abdusco
abdusco / RollingHash.cpp
Last active December 22, 2018 19:16
RollingHash
#include "RollingHash.h"
RollingHash::RollingHash(const std::string& text, unsigned long wordLength) : text(text) {
this->textLength = text.size();
this->wordLength = wordLength;
hash = 0;
initHash();
windowStart = 0;
@abdusco
abdusco / singleton.py
Created November 21, 2018 15:32
Run only a single instance of given function
import tempfile
import os
from pathlib import Path
def singleton(callback: callable, instance_name: str):
tempdir = Path(tempfile.gettempdir())
lockfile = tempdir / f'{instance_name}.lock'
try:
if lockfile.exists():
@abdusco
abdusco / session_event_listener.py
Created November 21, 2018 08:08
Listen to workstation lock and unlock events in Python (tested on W10)
from collections import defaultdict
from enum import Enum
import win32api
import win32con
import win32gui
import win32ts
class SessionEvent(Enum):
ANY = 0
@abdusco
abdusco / active_desktop.py
Last active May 29, 2021 01:03
Enable ActiveDesktop and set wallpaper with fade effect on Windows (tested on W10)
import ctypes
from win32com.shell import shell, shellcon
import pythoncom
def enable_active_desktop():
"""
Taken from:
https://stackoverflow.com/a/16351170
@abdusco
abdusco / question-1.md
Last active May 4, 2018 15:07
CMPE321 Spring 2018

BOUN CMPE321 Spring 2018 MT2 Questions

1st Question

In SQL and a language that you've learned in this course write the expressions for the names of publishers who published every book in Book relation.

BOOK(isbn*, title, ...)
PUBLISH(isbn*, publ_name*, year*)