Skip to content

Instantly share code, notes, and snippets.

View vladiibine's full-sized avatar

Vlad George Ardelean vladiibine

  • Cluj, Romania
View GitHub Profile
# It will be slightly harder to create multiple instances of this class
class S:
def __init__(self, arg1, arg2):
# Dummy method. Used for reflection only
pass
@classmethod
def get_instance(cls, arg1, arg2):
# Dummy method. Used for reflection only
def algorithmic_chance_men_in_group(pop_size, sample_size, num_men):
"""Used to estimate the odds of selecting `num_men` men out of
a population of size `pop_size`, when taing a sample of size
`sample_size`
Usage:
>>> chance_as_percent = algorithmic_chance_men_in_group(30000, 1000, 600)[0]
"""
# assuming that 50% of the pop is men
numerator = 1
"""
Examples of usage of the twisted library
"""
from datetime import timedelta, datetime
# Step 1:
# create a server that each time it receives a http request, it will return "hello"
from twisted.web import server, resource
from twisted.internet import reactor
@vladiibine
vladiibine / vlad_trie.py
Created May 24, 2019 21:36
Trie for storing text. Very inefficient memory-wise
import copy
import unittest
class Node:
__slots__ = ["count", "next"]
def __init__(self, count, next_):
self.count = count
self.next = next_
var print = function( o, maxLevel, level )
{
if ( typeof level == "undefined" )
{
level = 0;
}
if ( typeof maxlevel == "undefined" )
{
maxLevel = 0;
}
# List all the console_scripts entry points in the given distribution, or all distributions if None
def list_entry_points(desired_distribution=None):
all_entry_maps = {}
for key, distribution in pkg_resources.working_set.by_key.items():
if desired_distribution and distribution.key != desired_distribution:
continue
distribution_entrypoints = distribution.get_entry_map()
@vladiibine
vladiibine / sysdig-commands.md
Last active April 6, 2016 14:48
sysdig commands

#Get help here http://www.sysdig.org/wiki/sysdig-user-guide/

Show every time a file is opened under /etc.

sudo sysdig evt.type=open and fd.name contains /etc

Sysdig output format

*%evt.num %evt.time %evt.cpu %proc.name (%thread.tid) %evt.dir %evt.type %evt.args

@vladiibine
vladiibine / swap_django_auth_user.md
Last active March 9, 2020 20:59
Swap django auth.User with custom model after having applied the 0001_initial migration

Swapping the django user model during the lifecycle of a project (django 1.8 guide)

I've come to a point where I had to swap django's user model with a custom one, at a point when I already had users, and already had apps depending on the model. Therefore this guide is trying to provide the support that is not found in the django docs.

Django warns that this should only be done basically at the start of a project, so that the initial migration of an app includes the creation of the custom user model. It took a while to do, and I ran into problems created by the already existing relations between other models and auth.User.

There were good and not so good things regarding my project state, that influenced the difficulty of the job.

Things that made the swap simpler
  1. My custom user also had an id field, that's just a usual default django id