Skip to content

Instantly share code, notes, and snippets.

View Prodge's full-sized avatar

Prodge Prodge

View GitHub Profile
#!/usr/bin/env python
"""
Restart router when it goes offline
Runs on orange pi zero v1
"""
import os
import sys
if not os.getegid() == 0:
@Prodge
Prodge / threading.py
Last active July 26, 2017 09:19
Python Implementations for Compose / Comp, 'Thread First', 'Thread Last' and 'Thread As'
def equals(value):
'''
Returns a function that when called will check the called value with the given value for equality
'''
return lambda called_value: value == called_value
def reverse(collection):
return collection[::-1]
@Prodge
Prodge / thread_tools.py
Created July 26, 2017 08:27
Python 'Thread First', 'Thread Last' and 'Thread As' Functions - no dependencies
def thread_first(value, *forms):
'''
Returns the given value threaded through the given collection of forms as the first argument.
A form is a function or a tuple containing a function as its first element and a list of arguments.
The return value of the previously called function will be threaded in as the first argument to the next function.
Use this to flatten nested function calls.
Example:
>>> def add(a, b):
@Prodge
Prodge / filter.py
Created February 17, 2017 01:59
Filter implementation using reduce in python
def my_filter(fn, coll):
reduce(lambda out, x: out + ([x] if fn(x) else []), coll, [])
@Prodge
Prodge / map.py
Created February 17, 2017 01:56
Map implementation using reduce in Python
def my_map(fn, coll):
reduce(lambda out, x: out + [fn(x)], coll, [])
@Prodge
Prodge / handlers.clj
Last active February 16, 2017 12:41
re-frame go-swap effect: Push the result pulled from a channel into the db
; Requires this event handler
(reg-event-db :db-swap
(fn [db [_ func value]]
(func db value)))
;The go-swap effect
(reg-fx :go-swap
@Prodge
Prodge / .vimrc
Last active June 21, 2022 09:11
Vim hjkl navigation remapping for dvorak users
" Add this to your vimrc
" New mappings: c
" h t n
" This also integrates this mapping into insert mode via <Alt>
"Navigation for dvorak
@Prodge
Prodge / merge.py
Last active August 12, 2016 03:06
Python: Merge two lists recursivley alternating between the heads of each list
def merge_lists_into_string(a, b, string):
'''
Takes two lists of varying size and merges them like so:
([1,2,3], [10, 20, 30, 40, 50]) >> [1, 10, 2, 20, 3, 30, 40, 50]
'''
if a:
string += a.pop(0)
if b:
string += b.pop(0)
if a or b:
while (!(response=cdoi.receiveMessageFromServer()).equals (new String ())) System.out.println(response);
<!DOCTYPE html>
<meta charset="UTF-8">
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="style/main.css">
</head>
<body>