Skip to content

Instantly share code, notes, and snippets.

View codenameyau's full-sized avatar

Jorge Yau codenameyau

View GitHub Profile

The Magic of Maybe

The Pattern

Consider the following code

def do_some_stuff(x)
  try:
    val = f(x)
  except NameError, e:
    val = False
  return va;
@codenameyau
codenameyau / lambda_vs_list_comprehension.py
Last active June 29, 2017 15:34
Python lambda vs list comprehension
################################################################
# BASICS: LAMBDA VS LIST COMPREHENSION
################################################################
# Filter
filter(lambda x: x % 2, range(10))
[x for x in range(10) if x % 2]
# Map
map(lambda x: x*x, range(10))
@codenameyau
codenameyau / auto-child-width.css
Created May 18, 2015 20:51
Autofill children width to fill parent
/*!
* Description:
* Fill variable child containers to 100% width
* http://stackoverflow.com/a/5862782
*/
.control-container {
width: 100%;
display: table;
table-layout: fixed;
function A = generate_a( N )
% Generates matrix A
% N: Integer of size of mesh
n = N-1;
meshsize = n*n;
% Build matrix D
D_block = triu(tril(ones(n), 1), -1) - 5*eye(n);
D_repeat = repmat({D_block}, n, 1);
D_matrix = blkdiag(D_repeat{:});