Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Daniel Sposito dsposito

🚀
View GitHub Profile
@ipmb
ipmb / settings.py
Last active Dec 26, 2020
Django logging example
View settings.py
import logging.config
import os
from django.utils.log import DEFAULT_LOGGING
# Disable Django's logging setup
LOGGING_CONFIG = None
LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper()
logging.config.dictConfig({
anonymous
anonymous / illuminate-support-loc.txt
Created Apr 21, 2016
illuminate/support LOC
View illuminate-support-loc.txt
phploc 3.0.0 by Sebastian Bergmann.
Directories 3
Files 51
Size
Lines of Code (LOC) 5756
Comment Lines of Code (CLOC) 2422 (42.08%)
Non-Comment Lines of Code (NCLOC) 3334 (57.92%)
Logical Lines of Code (LLOC) 790 (13.72%)
@miohtama
miohtama / secure_uuid.py
Created Jul 30, 2015
Generate full 128-bit randomness UUID version 4 on Python, break spefification to stir extra 6 bits of randomness
View secure_uuid.py
def secure_uuid():
"""Create a non-conforming 128-bit random version 4 UUID.
Random UUID is a RFC 4122 compliant UUID version 4 128-bit number. By default 6 fixed bits, 4 bits for version and 2 bits reserved for other purposes, are fixed. This function behaves like Python's ` uuid4()`` but also randomizes the remaining six bits, generating up to 128 bit randomness.
This function also sources all bytes from `os.urandom()` to guarantee the randomness and security and does not rely operating system libraries.
Using ``secure_uuid()`` poses a risk that generated UUIDs are not accepted when communicating with third party system. However, they are observed to be good for URLs and to be stored in PostgreSQL.
More information
@waylonflinn
waylonflinn / install-python-data-science.sh
Last active Dec 4, 2016
Install Data Science and NLP libraries for python3 in a virtualenv (Numpy, Scipy, Matplotlib, Pandas, Gensim, OpenBLAS and PyTables)
View install-python-data-science.sh
#!/usr/bin/env bash
## create an ubuntu 14.04 hvm instance, then from your home directory:
# 1. download this script
# wget https://gist.githubusercontent.com/waylonflinn/506f563573600d944923/raw/install-python-data-science.sh
# 2. make it executable
# chmod a+x install-python-data-science.sh
@timster
timster / auth_views.py
Last active Sep 24, 2020
Class-based views for Flask
View auth_views.py
from flask import Blueprint
from flask import url_for
from flask.ext.login import current_user
from flask.ext.login import login_user
from flask.ext.login import logout_user
from flask.ext.login import login_required
from forms import LoginForm
from forms import ForgotPasswordForm
from forms import ResetPasswordForm
@kwatch
kwatch / gist:02b1a5a8899b67df2623
Last active Oct 15, 2020
Example to support 'geometry' type (on PostgreSQL) in SQLAlchemy
View gist:02b1a5a8899b67df2623
from sqlalchemy import func
from sqlalchemy.types import UserDefinedType, Float
class EasyGeometry(UserDefinedType):
def get_col_spec(self):
return "GEOMETRY"
def bind_expression(self, bindvalue):
@redox
redox / base.html.haml
Last active May 16, 2020
Algolia extends HipChat to customer support
View base.html.haml
#chat-box.ubuntu.hidden-xs
.closed
.pull-right
= link_to_function content_tag(:i, nil, class: 'glyphicon glyphicon-chevron-up').html_safe, 'chat.show()'
.m-l-small
= link_to_function 'Chat with us', 'chat.show()'
.opened{style: 'display: none'}
.header
.pull-right
= link_to_function content_tag(:i, nil, class: 'glyphicon glyphicon-plus-sign').html_safe, 'chat.maximize()', class: 'maximize', style: 'display: none'
@lttlrck
lttlrck / gist:9628955
Created Mar 18, 2014
rename git branch locally and remotely
View gist:9628955
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
View summary_tool.py
# coding=UTF-8
from __future__ import division
import re
# This is a naive text summarization algorithm
# Created by Shlomi Babluki
# April, 2013
class SummaryTool(object):
@nikic
nikic / objects_arrays.md
Last active Nov 17, 2020
Post explaining why objects often use less memory than arrays (in PHP)
View objects_arrays.md

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't: