Skip to content

Instantly share code, notes, and snippets.

View kpsychas's full-sized avatar

Konstantinos Psychas kpsychas

View GitHub Profile
@rcshubhadeep
rcshubhadeep / trie.py
Last active June 11, 2022 01:23
trie implementation in Python3
from typing import Tuple
class TrieNode(object):
"""
Our trie node implementation. Very basic. but does the job
"""
def __init__(self, char: str):
self.char = char
@rushilgupta
rushilgupta / GoConcurrency.md
Last active May 14, 2024 06:30
Concurrency in golang and a mini Load-balancer

INTRO

Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".

Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).

Let's dig in:

Goroutines

@mirekfranc
mirekfranc / profile-and-debug.py
Last active August 29, 2015 14:20
How to profile and debug python script
##################################################
# profiler:
# https://docs.python.org/2/library/profile.html
# python -mcProfile -o profiler.out ./something.py
### profile.py ###
import pstats
p = pstats.Stats('profiler.out')
p.sort_stats('cumtime').print_stats(20)
@lebedov
lebedov / prof_dec.py
Created July 21, 2014 15:01
Decorator for profiling functions.
import cProfile
import functools
def do_cprofile(*dec_args):
"""
Decorator for profiling functions.
If a file name is passed to the decorator as an argument, profiling data
will be written to that file; otherwise, it will be displayed on the screen.
"""
@lebedov
lebedov / ipynb_renumber.py
Last active March 15, 2020 21:10
Consecutively renumber prompts in an IPython notebook.
#!/usr/bin/env python
"""
Consecutively renumber prompts in an IPython notebook.
"""
# Copyright (c) 2015, Lev Givon
# All rights reserved.
# Distributed under the terms of the BSD license:
# http://www.opensource.org/licenses/bsd-license
@atsuya046
atsuya046 / strategy.py
Created January 21, 2014 04:47
GoF design pattern with Python. - Strategy
# http://stackoverflow.com/questions/963965/how-is-this-strategy-pattern
# -written-in-python-the-sample-in-wikipedia
"""
In most of other languages Strategy pattern is implemented via creating some
base strategy interface/abstract class and subclassing it with a number of
concrete strategies (as we can see at
http://en.wikipedia.org/wiki/Strategy_pattern), however Python supports
higher-order functions and allows us to have only one class and inject
functions into it's instances, as shown in this example.
"""
@aras-p
aras-p / preprocessor_fun.h
Last active June 21, 2024 12:20
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@damianavila
damianavila / remove_output.py
Created April 3, 2013 22:05
Remove output from IPython notebook from the command line (dev version 1.0)
"""
Usage: python remove_output.py notebook.ipynb [ > without_output.ipynb ]
Modified from remove_output by Minrk
"""
import sys
import io
import os
from IPython.nbformat.current import read, write
@durden
durden / dump_stats.py
Created December 12, 2012 23:02
Dump Python pstats file to stdout sorted by cumulative stat
if __name__ == "__main__":
import sys
import pstats
stats = pstats.Stats(sys.argv[1])
stats.strip_dirs()
stats.sort_stats('cumulative')
stats.print_stats()
@arvearve
arvearve / gist:4158578
Created November 28, 2012 02:01
Mathematics: What do grad students in math do all day?

Mathematics: What do grad students in math do all day?

by Yasha Berchenko-Kogan

A lot of math grad school is reading books and papers and trying to understand what's going on. The difficulty is that reading math is not like reading a mystery thriller, and it's not even like reading a history book or a New York Times article.

The main issue is that, by the time you get to the frontiers of math, the words to describe the concepts don't really exist yet. Communicating these ideas is a bit like trying to explain a vacuum cleaner to someone who has never seen one, except you're only allowed to use words that are four letters long or shorter.

What can you say?