Skip to content

Instantly share code, notes, and snippets.

@ehborisov
ehborisov / Spark Dataframe Cheat Sheet.py
Last active Oct 12, 2020 — forked from AlessandroChecco/Spark Dataframe Cheat Sheet.py
Cheat sheet for Spark Dataframes (using Python)
View Spark Dataframe Cheat Sheet.py
# A simple cheat sheet of Spark Dataframe syntax
# Current for Spark 1.6.1
# import statements
#from pyspark.sql import SQLContext
#from pyspark.sql.types import *
#from pyspark.sql.functions import *
from pyspark.sql import functions as F
#SparkContext available as sc, HiveContext available as sqlContext.
View binary_search_tree.py
# BST is a linked data structure in which each node is an object.
# In addition to a key and satellite data, each node contains attributes left, right, and p
# that point to the nodes corresponding to its left child and its parent.
# BST property
# x is a node in BST if y is any node in a left subtree than y.key <= x.key if y is any node in a right subtree
# than y.key >= x.key
class Node(object):
View rooted_unbounded_tree.py
"""
Rooted tree with unbounded branching, left child - right sibling representation backed by 4 arrays.
"""
class UnboundedTree(object):
def __init__(self):
self.root = 0
self.storage = [
View binary_heap.py
class MinHeap(object):
def __init__(self):
self.storage = []
def add(self, val):
self.storage.append(val)
self._percolate_up()
def get_min(self):
View linked_lists.py
# Linked lists are data structures made of chained elements connected either with one or with two others.
from collections import namedtuple
# Singly linked list node (immutable)
_Node = namedtuple('Node', ['value', 'next'])
# or mutable
View balanced_parantheses_combinations.py
def parentheses_combinations_brute_force_1(n):
ans = []
def generate_all(candidate):
if len(candidate) == 2 * n:
if is_valid(candidate):
ans.append(''.join(candidate))
else:
candidate.append(')')
generate_all(candidate)
View n_queens.py
def solveNQueens(n):
"""
Returns all possible combinations of N queens placement.
:type n: int
:rtype: List[List[str]]
"""
board = [['.'] * n for _ in range(n)]
solutions = []
View linked_list_is_a_palindrome.py
import sys
import collections
Node = collections.namedtuple('Node', ['value', 'next'])
def check_palindrome_n2(head_node):
seen = []
if not head_node.next:
return True
View WaitingStatement.java
package io.qameta.htmlelements.handler;
import com.google.common.base.Throwables;
import org.openqa.selenium.support.ui.Clock;
import org.openqa.selenium.support.ui.SystemClock;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
View WebBlockMethodHandler.java
package io.qameta.htmlelements.handler;
import io.qameta.htmlelements.context.Context;
import io.qameta.htmlelements.context.Store;
import io.qameta.htmlelements.exception.MethodInvocationException;
import io.qameta.htmlelements.exception.NotImplementedException;
import io.qameta.htmlelements.extension.TargetModifier;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;