Skip to content

Instantly share code, notes, and snippets.

@abdusco
abdusco / ProcessDashboard.module.php
Last active February 8, 2018 17:24
A simple dashboard module for ProcessWire 3.0+
<?php namespace ProcessWire;
class ProcessDashboard extends Process implements Module
{
public static function getModuleInfo()
{
return [
'title' => 'Orders Dashboard',
'summary' => 'Shows latest orders',
@abdusco
abdusco / limitImageFieldMaxFiles.php
Created September 19, 2017 07:01
Limit Image field to maximum 1 file for a template in ProcessWire
<?php namespace ProcessWire;
// put this in /site/ready.php
wire()->addHookAfter('ProcessPageEdit::buildForm', function (HookEvent $e) {
/** @var ProcessPageEdit $edit */
$templates = ['post', 'basic'];
$edit = $e->object;
$page = $edit->getPage();
@abdusco
abdusco / multiplePrependAppendFiles.php
Created September 19, 2017 07:02
Append/prepend multiple files to template file in ProcessWire
<?php namespace ProcessWire;
wire()->addHookBefore('PageRender::renderPage', function (HookEvent $e) {
/** @var Page $page */
/** @var HookEvent $event */
/** @var Template $template */
$event = $e->arguments(0);
$options = $event->arguments(0);
$page = $event->object;
@abdusco
abdusco / removeTemplateOptions.php
Created October 4, 2017 18:45
Remove changeable template options from Page editor
<?php
wire()->addHookAfter('ProcessPageEdit::buildFormSettings', function (HookEvent $e) {
$page = $e->object->getPage();
if ($page->template != "basic") return;
/** @var $templatesField InputfieldSelect */
$templatesField = $e->return->children->get('id=template');
$templates = $templatesField->getOptions();
@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*)
@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 / 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 / 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 / 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;

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',