Skip to content

Instantly share code, notes, and snippets.

View MaxMorais's full-sized avatar
🏢
Building Solutions in Tech

Maxwell Morais MaxMorais

🏢
Building Solutions in Tech
View GitHub Profile

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@aliles
aliles / context.py
Created February 17, 2014 11:20
Class switching context object to prevent applications for assigning to protected properties. Uses class swizzling.
"Program execution context"
import warnings
class SwizzleContext(object):
"""Type switching context object base class
Supports the context manager protocol to switch the instance from a
MutableContext to the protected Context.
"""
@BertrandBordage
BertrandBordage / paradox.py
Last active May 31, 2024 12:46
Python Paradox database reader
# coding: utf-8
"""
Converts Paradox databases to Python objects or CSV.
You don't need any dependency (except Python) to make this module work.
This module is incomplete but reads most Paradox `.DB` files.
If this module is not fast or complete enough for you, consider using pxview.
"""
@JuniorPolegato
JuniorPolegato / calcular_formula.py
Last active May 29, 2020 02:46
Exemplo de script para se calcular qualquer fórmula, exemplo com juros compostos
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import re
# dado um título e lista de listas no formato
# ('<variável>', '<tipo>', '<descricao>', '<fórmula>')
# pede-se qual variável calcular, pede os valores e dá o resultado
# qualquer valor vazio saida da função
@uroshekic
uroshekic / tkinter-autocomplete-listbox.py
Last active March 22, 2023 07:18
Tkinter - Autocomplete Entry Field
"""
Inspired by http://code.activestate.com/recipes/578253-an-entry-with-autocompletion-for-the-tkinter-gui/
Changes:
- Fixed AttributeError: 'AutocompleteEntry' object has no attribute 'listbox'
- Fixed scrolling listbox
- Case-insensitive search
- Added focus to entry field
- Custom listbox length, listbox width matches entry field width
- Custom matches function
"""
@drgarcia1986
drgarcia1986 / main.py
Last active August 29, 2015 14:02
[python-brasil] carregar processo independente
>>> import os
>>> programa = r'C:\Program Files (x86)\mongoDB\bin\mongod.exe'
>>> parametros = r'--logpath "C:\Foo\Bar\Base\install.log" --dbpath "C:\Foo\Bar\Base\data\db" --port 1124'
>>> os.path.dirname(programa)
'C:\\Program Files (x86)\\mongoDB\\bin'
>>> os.path.basename(programa)
'mongod.exe'
>>> os.spawnl(os.P_WAIT, os.path.dirname(programa), os.path.basename(programa), parametros)
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
@SevenW
SevenW / HTTPWebSocketsHandler.py
Last active October 23, 2023 13:10
HTTPWebSocketsHandler extends SimpleHTTPServer with WebSockets enabling the use of HTTP and WebSockets throught the same port
'''
The MIT License (MIT)
Copyright (C) 2014, 2015 Seven Watt <info@sevenwatt.com>
<http://www.sevenwatt.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@austinhyde
austinhyde / js-observables-binding.md
Last active August 16, 2023 18:19
Vanilla JavaScript Data Binding

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);

frappe.ui.form.on("Quotation", "refresh", function(frm, doctype, name) {
cur_frm.add_custom_button(__('Add Interaction'), function() {
var d = frappe.prompt([
{label:__("Type of Interaction"), fieldtype:"Select",
options: ["SMS", "Call", "Visit", "Webex"],
fieldname:"type_of_interaction"},
{label:__("Result"), fieldtype:"Select", options: ["Status Quo", "Warmer", "Colder"], fieldname:"result"},
{fieldtype: "Column Break"},
{'fieldname': 'responce_reson', 'fieldtype': 'Data', 'label': 'Responce Reson', 'reqd': 0},
{'fieldname': 'next_date', 'fieldtype': 'Date', 'label': 'Next Action Date', 'reqd': 0},
@palankai
palankai / specification.py
Last active March 29, 2024 10:02
Python Specification Pattern
class Specification:
def __and__(self, other):
return And(self, other)
def __or__(self, other):
return Or(self, other)
def __xor__(self, other):
return Xor(self, other)