Skip to content

Instantly share code, notes, and snippets.

View mfbx9da4's full-sized avatar

David Alberto Adler mfbx9da4

View GitHub Profile
app.factory('socket', function($rootScope) {
var socket = io.connect();
return socket;
});
@mfbx9da4
mfbx9da4 / index.html
Created May 24, 2017 21:38
testing on jsbin Unit testing template // source http://jsbin.com/rovase
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Unit testing template">
<meta charset="utf-8">
<title>testing on jsbin</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/mocha/1.18.2/mocha.css">
</head>
<body>
<div id="mocha"></div>
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="details.xsl"?>
<gpx
version="1.1"
creator="Strava Android Application"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:topografix="http://www.topografix.com/GPX/Private/TopoGrafix/0/1" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.topografix.com/GPX/Private/TopoGrafix/0/1 http://www.topografix.com/GPX/Private/TopoGrafix/0/1/topografix.xsd">
<trk>
<name><![CDATA[Evening Ride]]></name>
@mfbx9da4
mfbx9da4 / has_cycle.py
Created March 4, 2018 04:27
Check if graph has cycle in python
from collections import OrderedDict
def has_cycle_rec(graph, node, parents = None):
parents = parents or set()
parents.add(node)
for child in graph[node]:
if child in parents or has_cycle_rec(graph, child, parents):
return True
parents.remove(node)
return False
@mfbx9da4
mfbx9da4 / has_cycle.py
Created March 4, 2018 04:27
Check if graph has cycle in python
from collections import OrderedDict
def has_cycle_rec(graph, node, parents = None):
parents = parents or set()
parents.add(node)
for child in graph[node]:
if child in parents or has_cycle_rec(graph, child, parents):
return True
parents.remove(node)
return False
@mfbx9da4
mfbx9da4 / has_cycle.py
Created March 4, 2018 04:27
Check if graph has cycle in python
from collections import OrderedDict
def has_cycle_rec(graph, node, parents = None):
parents = parents or set()
parents.add(node)
for child in graph[node]:
if child in parents or has_cycle_rec(graph, child, parents):
return True
parents.remove(node)
return False
@mfbx9da4
mfbx9da4 / check_cycle_by_removing_leaves.py
Created March 4, 2018 04:28
Check if graph has cycle by removing leaves
from collections import DefaultDict
# an acyclic graph will always have a leaf node
# cycle graph will not
def solve(graph, node):
# sum to n = ((n + 1) * n / 2)
# if edges max is n
# if edges > n * (n-1)/2
#
@mfbx9da4
mfbx9da4 / BackgroundLocationViewController.swift
Last active March 4, 2018 20:51
An ios app which continuously tracks and logs location in the background
//
// ViewController.swift
// GPS Tracker
//
// Created by David Adler on 04/03/2018.
// Copyright © 2018 David Adler. All rights reserved.
//
// - Blog overview https://www.raywenderlich.com/143128/background-modes-tutorial-getting-started
// - Background location in swift https://stackoverflow.com/a/45567876/1376627
// - Conforming to delegate https://stackoverflow.com/questions/35900126/cannot-assign-value-of-type-appdelegate-to-type-cllocationmanagerdelegate
@mfbx9da4
mfbx9da4 / longest_common_prefix.py
Last active March 17, 2018 19:27
Return the length of the longest common prefix for a set of strings
from timer import Timer
import matplotlib.pyplot as plt
class Solution(object):
def longestCommonPrefix(self, strings):
if not len(strings):
return 0
if len(strings) == 1:
return len(strings[0])
import pprint
# treasure finding game
# 2d board = array of arrays
# initialized with num rows, num cols
# treasure position (row, col)
# all positions hidden, player reveals positions
# player starts where he wants
# betting site, find treasure on board
# step to next user