Skip to content

Instantly share code, notes, and snippets.

View macagua's full-sized avatar
🏠
Working from home

Leonardo J. Caballero G. macagua

🏠
Working from home
View GitHub Profile
@fxbenard
fxbenard / getpomakemo.sh
Last active November 9, 2016 14:53
Script to pull translations with Transifex client and create the mo files.
#! /bin/sh
# Pull all files;
# Minimum percentage change to whatever you want
tx pull -a --minimum-perc=100
# Create .mo files from .po files.
# Twisted by WP-Translations.org, created by grappler.
for file in `find . -name "*.po"` ; do msgfmt -o ${file/.po/.mo} $file ; done
@stuart11n
stuart11n / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@Avinash-Raj
Avinash-Raj / ndis-fix.sh
Last active September 12, 2016 05:20
Shell script to fix "Install NDIS driver failed" error while trying to install Huawei modem drivers on linux
#!/bin/bash
# Run the below script only after "Install NDIS driver failed" error while trying to install Huawei modem drivers on linux.
# I checked this script on Ubuntu.
# Detailed explanation of this script was given here(http://askubuntu.com/a/414401/202806).
path="/usr/local/Mobile_Partner/driver"
if [ "$(ls -A $path)" ]; then
tput setaf 6; echo "Huawei modem drivers for linux are already installed on your pc.Please wait for NDIS driver installation."; tput sgr0
perl -i -pe 's#^(\s*dbg \("can.t kmalloc dev"\);)#//$1#' /usr/local/Mobile_Partner/driver/ndis_driver/ndis_src/src/hw_cdc_driver.c
cd $path
@kottenator
kottenator / multiple_select_field.py
Last active June 24, 2020 01:52
Django's multiple-choice model field with static choices
"""
Field with multiple *static* choices (not via m2m)
Value is stored in DB as comma-separated values
Default widget is forms.CheckboxSelectMultiple
Python value: list of values
Original Django snippet: https://djangosnippets.org/snippets/1200/
It's 6 years old and doesn't work with latest Django
Also it implements 'max_choices' functionality - I have removed it for simplicity
>>> from indico.modules.rb.models import Photo
>>> Photo.room
AttributeError: type object 'Photo' has no attribute 'room'
>>> db.session.query(Photo)
<sqlalchemy.orm.query.Query at 0x8211490>
>>> Photo.room
<sqlalchemy.orm.attributes.InstrumentedAttribute at 0x81c8090>
@simonedeponti
simonedeponti / utils.py
Last active August 29, 2015 14:01
Get all interfaces and behaviors
from zope.schema import getFields
from zope.interface import providedBy
from zope.interface import implementedBy
from zope.component import getUtility
from zope.component import queryUtility
from plone.behavior.interfaces import IBehavior
from plone.behavior.interfaces import IBehaviorAssignable
from plone.dexterity.interfaces import IDexterityFTI
from plone.dexterity.utils import resolveDottedName
@derhuerst
derhuerst / intro.md
Last active May 8, 2025 16:58
Installing Git on Linux, Mac OS X and Windows
@pawl
pawl / bindparameters.py
Created August 6, 2014 18:52
Use List In Bind Parameters - SQLAlchemy
my_list = ['peach', 'grape', 'apple']
query_parameters = {}
counter = 1
for list_item in my_list:
query_parameters["list_item" + str(counter)] = list_item
counter += 1
where_clause = 'fruits IN(:' + ",:".join(query_parameters.keys()) + ')' # create clause to be inserted into query
query_text = db.text("""
SELECT
@goldsborough
goldsborough / database.py
Created September 3, 2014 10:07
Python Sqlite3 wrapper
###########################################################################
#
## @file database.py
#
###########################################################################
import sqlite3
###########################################################################
#
@JulienBlancher
JulienBlancher / filter.d_nginx-auth.conf
Last active January 29, 2025 00:02
Fail2ban Config with Nginx and SSH
#
# Auth filter /etc/fail2ban/filter.d/nginx-auth.conf:
#
# Blocks IPs that makes too much accesses to the server
#
[Definition]
failregex = ^<HOST> -.*"(GET|POST).*HTTP.*"
ignoreregex =