Skip to content

Instantly share code, notes, and snippets.

@abubelinha
abubelinha / Caddyfile
Created December 16, 2023 12:45 — forked from jpoehls/Caddyfile
Caddyfile PHP on Windows
# http://caddyserver.com/download
http://localhost:8080 {
startup php.cmd &
fastcgi / 127.0.0.1:9123 php
}
@abubelinha
abubelinha / geojson-test.py
Created November 27, 2023 13:18 — forked from alanorth/geojson-test.py
Checking if GPS points are in a polygon with Shapely
#!/usr/bin/env python
#
# Given the three points below, this code prints:
#
# $ ~/src/geojson-test.py
# True
# True
# False
#
# Requires shapely to be installed in the virtual environment.
@abubelinha
abubelinha / dspace6-post-item-rest.md
Created November 27, 2023 13:15 — forked from alanorth/dspace6-post-item-rest.md
POSTing items to the DSpace 6 REST API

POSTing an item to /collections

First log in to get the JSESSIONID cookie and then post the item (I'm using httpie instead of curl):

$ http -f POST https://dspacetest.cgiar.org/rest/login [email protected] password=fuuuu
$ http https://dspacetest.cgiar.org/rest/status Cookie:JSESSIONID=EABAC9EFF942028AA52DFDA16DBCAFDE
$ http POST https://dspacetest.cgiar.org/rest/collections/f10ad667-2746-4705-8b16-4439abe61d22/items Cookie:JSESSIONID=EABAC9EFF942028AA52DFDA16DBCAFDE < item-object.json
HTTP/1.1 200 OK
Connection: keep-alive
Content-Encoding: gzip
@abubelinha
abubelinha / convert-docx-to-html.py
Created April 10, 2023 08:24 — forked from phillipkent/convert-docx-to-html.py
Python code using the python-docx module to convert a DOCX file to HTML
# Converts a docx file with tables and images to (simple) HTML
# ORIGINAL CODE BY DAVID SSALI AT SOURCE: https://medium.com/@dvdssali/docx-to-html-1374eb6491a1
#
# Requires the Python module 'python-docx' <https://python-docx.readthedocs.io>
#
# Example use:
# >>> s = convert('./SOURCEDIR', 'SAMPLE.docx')
# >>> print(s)
# or
# $ python .\convert-docx-to-html.py > temp.html
@abubelinha
abubelinha / isbn_lookup.py
Created February 25, 2023 08:50 — forked from miladkiaee/isbn_lookup.py
A simple ISBN lookup that uses Python and the Google Books API to display basic information about a book.
import urllib.request
import json
## import textwrap
import sqlite3
database = sqlite3.connect(':memory:')
cur = database.cursor()
def pma_import_resubmit(br, sqlfile, target_dbname):
""" To be used in phpmyadmin dump.sql file imports using python-mechanize
as described in <https://github.com/phpmyadmin/phpmyadmin/issues/17423#issuecomment-1268271930>
Only call this function when you have already found a 'timeout_passed=' string in browser response
(so you are sure the page contains a resubmit link)
"""
# https://stackoverflow.com/questions/3569622/python-mechanize-following-link-by-url-and-what-is-the-nr-parameter/3569707#3569707
#link = br.find_link(url = resumeurl)
link = br.find_link(text = "resubmit the same file")
link.absolute_url = link.absolute_url.replace("&amp;","&").replace("?", "?db="+target_dbname+"&")
@abubelinha
abubelinha / esslinger.rb
Created July 31, 2022 08:32 — forked from kueda/esslinger.rb
Script to parse Esslinger's A Cumulative Checklist for the Lichen-forming, Lichenicolous and Allied Fungi of the Continental United States and Canada into machine-readable CSV
#encoding: utf-8
#
# Script to parse Esslinger's A Cumulative Checklist for the Lichen-forming,
# Lichenicolous and Allied Fungi of the Continental United States and Canada
# into machine-readable CSV.
#
# Esslinger's checklist (e.g.
# http://www.ndsu.edu/pubweb/~esslinge/chcklst/chcklst7.htm) is considered
# authoritative for North American lichens, but it's authored with MS Word and
# has incosistent formatting. This script attempts to smooth that out and
@abubelinha
abubelinha / inat-password.py
Last active July 31, 2022 08:24 — forked from kueda/inat-password.py
iNaturalist API Resource Owner Password Credentials Flow Example (Python)
def get_inat_access_token(username = None, password = None, app_id = None, app_secret = None, jwt=True):
""" Get iNaturalist access token to make authenticated api requests and access your private data.
Example posted in <https://groups.google.com/g/inaturalist/c/PNfHggqoIYs/m/Lk30rlzKBAAJ>
and forked from <https://gist.github.com/kueda/53ef93159c64de96ddc2>
Other Python-iNaturalist stuff:
- <https://github.com/pyinat/pyinaturalist/>
- <https://inaturalist.nz/posts/20991-20-oauth2-package-for-python-body-str-paramsxml>
- <https://www.inaturalist.org/journal/glmory/21331-python-upload-script>
- <https://www.inaturalist.org/journal/glmory/21539-updated-python-upload-script>
- <https://github.com/glmory/iNaturalist-Uploads>
@abubelinha
abubelinha / vcard2org-contacts.py
Created July 12, 2022 10:59 — forked from tmalsburg/vcard2org-contacts.py
A simple script for converting vCard files to org-contacts.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Written by Titus von der Malsburg <[email protected]>, March 2014.
# This is a simple script for converting vCard files to
# org-contacts. There is one mandatory argument: the name of the
# vCard file. The result is printed to standard out.
# Usage:

Migrate from PHP to Python

Hi all, recently I've decided to move on and learn Python programming. At first, I though that it would be very difficult but in fact... Not that much. So I've decided to write this little gist and show the main differences between both languages.

I will use try to follow the same order used on this website: https://pythonprogramming.net/introduction-to-python-programming/. It was really usefull to improve my understanding of Python programming.

To finish, I'm assuming that you already got basic knowledge in Object Oriented Programming and already got skills and understanding of PHP programming. This is not intended to explain you how to code in PHP but if you're coming from Python programming, then this gist might help you to migrate from Python to PHP.

Official documentations