Skip to content

Instantly share code, notes, and snippets.

View sergiogarciadev's full-sized avatar
I turn coffee into code (sometimes in bugs).

Sergio Garcia sergiogarciadev

I turn coffee into code (sometimes in bugs).
View GitHub Profile
@aaugustin
aaugustin / admin.py
Last active August 7, 2022 19:39
Read-only ModelAdmin for Django
from django.contrib import admin
class ReadOnlyModelAdmin(admin.ModelAdmin):
"""
ModelAdmin class that prevents modifications through the admin.
The changelist and the detail view work, but a 403 is returned
if one actually tries to edit an object.
@jeromer
jeromer / compassbearing.py
Last active February 21, 2024 13:31
compass bearing between two points in Python
# LICENSE: public domain
def calculate_initial_compass_bearing(pointA, pointB):
"""
Calculates the bearing between two points.
The formulae used is the following:
θ = atan2(sin(Δlong).cos(lat2),
cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong))
@yoavram
yoavram / pypdfx.py
Last active September 12, 2022 12:09
A python client to pdfx 1.0 a "Fully-automated PDF-to-XML conversion of scientific text" (http://pdfx.cs.man.ac.uk/). Written to be used in Markx, a scientific-oriented Markdown editor (https://github.com/yoavram/markx).
# pdfx usage: http://pdfx.cs.man.ac.uk/usage
# requests docs: http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
import requests # get it from http://python-requests.org or do 'pip install requests'
url = "http://pdfx.cs.man.ac.uk"
def pypdfx(filename):
'''
Filename is a name of a pdf file WITHOUT the extension
The function will print messages, including the status code,
@frxstrem
frxstrem / http_proxy_connect.py
Last active March 11, 2024 04:37
Establish a socket connection through an HTTP proxy in Python.
'''
Establish a socket connection through an HTTP proxy.
Author: Fredrik Østrem <frx.apps@gmail.com>
License:
Copyright 2013 Fredrik Østrem
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
@jareware
jareware / SCSS.md
Last active July 1, 2024 09:25
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import httplib
import re
import sys
import base64
import subprocess
import urllib
import lxml.etree
@pramsey
pramsey / pgsql-parallel-postgis.md
Last active December 6, 2015 21:04
Parallel Sequence Scan and PostGIS
@macournoyer
macournoyer / Output
Last active January 9, 2023 15:12
A Neural Network framework in 25 LOC
$ python xor.py
Training:
Epoch 0 MSE: 1.765
Epoch 100 MSE: 0.015
Epoch 200 MSE: 0.005
* Target MSE reached *
Evaluating:
1 XOR 0 = 1 ( 0.904) Error: 0.096
0 XOR 1 = 1 ( 0.908) Error: 0.092
1 XOR 1 = 0 (-0.008) Error: 0.008
@nepsilon
nepsilon / custom-ssh-banner.md
Last active December 22, 2018 17:50
Display a cool banner when you log in with SSH — First published in fullweb.io issue #39

Display a cool banner when you log in with SSH

SSH gives us a way to displaya custom welcome message when a user log in. You can make this message dynamic thanks to update-motd, but here we’ll talk about the SSH built-in feature.

Here is how to do in 3 steps:

Put your message in /etc/issue.net:

$ vim /etc/issue.net
@nepsilon
nepsilon / 3-python-module-you-can-use-on-cli.md
Last active February 19, 2017 13:35
3 Python modules you can use directly in the CLI — First published in fullweb.io issue #45

3 Python modules you can use directly on the CLI

1. Start a local webserver to serve the file of your current directory on the LAN:

# Python version 2.x:
python -m SimpleHTTPServer 
# Python version 3.x:
python3 -m http.server