Skip to content

Instantly share code, notes, and snippets.

View dideler's full-sized avatar

Dennis Ideler dideler

View GitHub Profile
@SumuduF
SumuduF / cake_cutting.py
Last active December 12, 2015 08:59
Solutions for Facebook Hacker Cup Round 2 I got stuck on problem 2 during the actual round due to a bit of a nasty off-by-one error (fixed below); in retrospect it would have been better to try #3 to have a chance at qualifying. Added solution to problem #3; essentially a standard DP on a tree + a bit of cleverness to ensure proper counting. Dur…
import sys
def main():
for (i, (n, a)) in enumerate(testcases()):
print "Case #{0}: {1}".format(i+1, regions(n, a))
def testcases(cin=sys.stdin):
nc = int(cin.next())
for _ in xrange(nc):
nums = map(int, cin.next().split())
@dideler
dideler / file_to_string.py
Created March 21, 2013 22:17
Playing around with different ways to read file contents into a string.
#!/usr/bin/env python
import sys
filename = sys.argv[1]
# These do not remove \n
with open(filename) as f:
s = ''.join(f.readlines())
@dideler
dideler / example.md
Last active February 17, 2024 20:24
A python script for extracting email addresses from text files.You can pass it multiple files. It prints the email addresses to stdout, one address per line.For ease of use, remove the .py extension and place it in your $PATH (e.g. /usr/local/bin/) to run it like a built-in command.

The program below can take one or more plain text files as input. It works with python2 and python3.

Let's say we have two files that may contain email addresses:

  1. file_a.txt
foo bar
ok ideler.dennis@gmail.com sup
 hey...user+123@example.com,wyd
hello world!
@dideler
dideler / Makefile
Last active April 8, 2024 04:16
An easy and quick way to encrypt (and decrypt) sensitive files on your computer. The filename is static, so don't forget to set it (on line 14)!
# Based on http://ejohn.org/blog/keeping-passwords-in-source-control/
#
# John Resig needed a way to keep sensitive data (e.g. config files with
# passwords) out of source control. So he decided to encrypt the sensitive data.
#
# I decided to modify the script so it's purpose is quickly encrypting or
# decrypting any sensitive file you have on your computer.
#
# Usage: make encrypt
# make decrypt
@dideler
dideler / _code_snippets.md
Last active January 6, 2024 15:11
Various snippets of code. Enjoy!

Snippets of code that I've played around with, which could be useful to others.
Nothing impressive, but you may learn a thing or two.

@dideler
dideler / inheritance.cpp
Last active March 20, 2017 21:13
C++ notes
class A
{
public:
int x;
protected:
int y;
private:
int z;
};
@dideler
dideler / 0-startup-overview.md
Last active May 3, 2024 11:03
Startup Engineering notes
@nodesocket
nodesocket / bootstrap.flatten.css
Last active April 1, 2021 23:37
Below are simple styles to "flatten" bootstrap. I didn't go through every control and widget that bootstrap offers, only what was required for https://commando.io, so your milage may vary.
/* Flatten das boostrap */
.well, .navbar-inner, .popover, .btn, .tooltip, input, select, textarea, pre, .progress, .modal, .add-on, .alert, .table-bordered, .nav>.active>a, .dropdown-menu, .tooltip-inner, .badge, .label, .img-polaroid {
-moz-box-shadow: none !important;
-webkit-box-shadow: none !important;
box-shadow: none !important;
-webkit-border-radius: 0px !important;
-moz-border-radius: 0px !important;
border-radius: 0px !important;
border-collapse: collapse !important;
background-image: none !important;
@goatslacker
goatslacker / gist:6004481
Created July 15, 2013 23:36
time tracking local
" Lets me know how much time I've spent editing a file
" Keyboard shortcut -> \dt
augroup TimeSpentEditing
au!
au BufWinEnter * if !exists('b:tstart')|let b:tstart=reltime()|en
augroup END
function! TimeSpentEditing()
let secs = str2nr(reltimestr(reltime(b:tstart)))
let hours = secs / 3600
@maxim
maxim / rails_load_path_tips.md
Last active April 13, 2023 13:28
How to use rails load paths, app, and lib directories.

In Rails 3

NOTE: This post now lives (and kept up to date) on my blog: http://hakunin.com/rails3-load-paths

If you add a dir directly under app/

Do nothing. All files in this dir are eager loaded in production and lazy loaded in development by default.

If you add a dir under app/something/