Skip to content

Instantly share code, notes, and snippets.

View shaypal5's full-sized avatar
🐢
Working away...

Shay Palachy-Affek shaypal5

🐢
Working away...
View GitHub Profile
@shaypal5
shaypal5 / clique_percolation.py
Last active January 24, 2017 19:44
Clique percolation in Python with no external dependencies.
"""Finds communities in the given graph using clique percolation."""
def _add_edge_to_adjancy_list(adjancy_list, node1, node2):
if node1 in adjancy_list:
adjancy_list[node1].add(node2)
else:
adjancy_list[node1] = set([node2])
@lopesivan
lopesivan / BUG.md
Created April 30, 2017 01:18
Install with pip (recommended)

You need a python 2.7 or 3.X distribution installed in your machine. Modern python distros come with pip pre-installed, if not, install pip following pip docs

Install conan:

$ pip install conan

BUG: pyenv: cannot rehash: ~/.pyenv/shims/.pyenv-shim exists

@shaypal5
shaypal5 / quiet_print_oneliner.py
Created October 18, 2018 11:17
Silence-able print one-liner for Python
def foo(a, quiet=False):
_print = (lambda x: x) if quiet else print
b = a * 5
_print("Warming up warp engines. This will not print if quiet is set to True.")
return b + 3.14
@dan-blanchard
dan-blanchard / .1.miniconda.md
Last active December 11, 2019 22:38
Quicker Travis builds that rely on numpy and scipy using Miniconda

For ETS's SKLL project, we found out the hard way that Travis-CI's support for numpy and scipy is pretty abysmal. There are pre-installed versions of numpy for some versions of Python, but those are seriously out of date, and scipy is not there are at all. The two most popular approaches for working around this are to (1) build everything from scratch, or (2) use apt-get to install more recent (but still out of date) versions of numpy and scipy. Both of these approaches lead to longer build times, and with the second approach, you still don't have the most recent versions of anything. To circumvent these issues, we've switched to using Miniconda (Anaconda's lightweight cousin) to install everything.

A template for installing a simple Python package that relies on numpy and scipy using Miniconda is provided below. Since it's a common s

#!/bin/bash
# --- Version history ---
# mrn: sleep for $freq instead of 3 seconds (forked)
# 0.4: added variable to store file path, and $2 for base file name
# added variable to store desired reporting interval
# 0.3: added $1 to send in process ID at run time.
# 0.2: switched to $SECONDS for the loop. works.
# 0.1: didn't work well at all.
# --- Version history ---
@shaypal5
shaypal5 / if_python_package.sh
Created July 21, 2018 17:00
bash if-else by Python package existence
# an example checking if the pandas package is installed
if python -c 'import pkgutil; exit(not pkgutil.find_loader("pandas"))'; then
echo 'pandas found'
else
echo 'pandas not found'
fi
@shaypal5
shaypal5 / readme_content_in_sphinx.rst
Last active March 28, 2023 17:08
Including parts of README.rst in your sphinx docs
@Jaza
Jaza / Private-pypi-howto
Last active July 2, 2023 16:24
Guide for how to create a (minimal) private PyPI repo, just using Apache with directory autoindex, and pip with an extra index URL.
*
@abhinav-upadhyay
abhinav-upadhyay / DateTimeDecoder.py
Last active July 4, 2023 13:12
A JSON decoder/encoder implementation for parsing dates as datetime objects in Python
#!/usr/bin/env python
# An example of decoding/encoding datetime values in JSON data in Python.
# Code adapted from: http://broadcast.oreilly.com/2009/05/pymotw-json.html
# Copyright (c) 2023, Abhinav Upadhyay
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@kyouko-taiga
kyouko-taiga / wrapper.py
Last active August 9, 2023 06:05
A python class wrapper to instrument/override properties
# This snippet was written by Dimitri Racordon (kyouko.taiga@gmail.com)
#
# Copyright (c) 2015 Dimitri Racordon
# Licensed under the The MIT License (MIT).
class lazy(object):
# This class is heavily inspired by the werkzeug.utils.cached_property
# decorator. It transforms a class method to a lazy property, evaluated
# the first time the property is accessed.