Skip to content

Instantly share code, notes, and snippets.

View kenmanheimer's full-sized avatar

Ken Manheimer kenmanheimer

View GitHub Profile
@kenmanheimer
kenmanheimer / sample
Created January 4, 2020 19:54
Scratch pyyaml for custom object export/import
def minimal_representer(dumper, item):
# type: (yaml.representer.Representer, spherical.item.Item) -> str
"""Minimal example of a representer that has features items will need."""
tag = "!spherical.example"
for i in spherical.utils.partially_sorted_partition(item):
fields = [['id', str(item._id)],
['title', item._title]]
return dumper.represent_sequence(tag, fields) # type: str
def g(n):
if n == 1:
return 4
elif n < 1:
raise ArithmeticError, "g can't do negative numbers"
else:
return g(n-1) * -3
@kenmanheimer
kenmanheimer / gist:72c08453b12c0d0a813f
Last active October 12, 2015 16:29 — forked from offby1/gist:1240799
git-grep in emacs
;; From https://gist.github.com/offby1/1240799
;; There's something similar (but fancier) in vc-git.el: vc-git-grep
;; -I means don't search through binary files
;; --no-color, oddly enough, is required to allow emacs to colorize the output
(defcustom git-grep-switches
"git --no-pager grep --extended-regexp -I -n --ignore-case --no-color"
(defun my-get-agent ()
"Establish my registered ssh agent in this emacs shell *and* emacs session."
(interactive)
(let ((process (get-buffer-process (current-buffer)))
beg end start-point)
(if (not process)
(error "Non-shell buffer")
(goto-char (process-mark process))
(insert "eval $(ga); echo SSH_AUTH_SOCK::$SSH_AUTH_SOCK::")
(comint-send-input)
# Adapted from a friend's alternative solution to the Madhava implementation problem
# from question 16 in the Interactive Python Textbook problem set:
# http://interactivepython.org/runestone/static/thinkcspy/Functions/thinkcspyExercises.html
# Original gist: https://gist.github.com/anonymous/2f78d796e965d6abcaec/321252a19d85aebca2359188d9991f7472e9f786
def myPi(tolerance=0.01):
"""Compute Pi by Madhava's technique, to specified tolerance, default .01."""
accumulator = 0
n = 0
newvalue = abs(tolerance) + 1
function dembase() {
var resolvefunc,
p1 = new Promise(
function (resolve) {resolvefunc = resolve})
.done(function() {console.log("p1 resolve")}),
r1 = resolvefunc,
p2 = new Promise(
function (resolve) {resolvefunc = resolve})
.done(function() {console.log("p2 resolve")}),
r2 = resolvefunc,
/** Show cordova .getFile() problem with some filenames containing "%" char.
*
* We create a file with the specified name in the Download dir,
* indicating whether or not the name of the created file is the same as
* that specified. On Android, the name is different if the specified
* one contains a sequence of chars starting with a "%" and not
* qualifying as a proper character entity - because of
* https://github.com/apache/cordova-plugin-file/blob/master/www/android/FileSystem.js#L29
*
* @param(string) filename - defaults to "x%y", which shows the problem.
diff --git a/src/views/FilesView.js b/src/views/FilesView.js
index 28cfcd7..04eaa8c 100644
--- a/src/views/FilesView.js
+++ b/src/views/FilesView.js
@@ -192,11 +192,11 @@
}
var model = this.model;
// Start by getting the folder path
- var path = "Download/" + s("SpiderOak") + "/.favorites/" +
- (spiderOakApp.accountModel.get("b32username") || "anonymous") +
@kenmanheimer
kenmanheimer / gist:6717382
Created September 26, 2013 17:17
much further - now consistently failing in transaction functionality integration tests
...
◦ should refuse invalid usernames:
 2) should refuse invalid usernames
◦ should refuse incorrect passphrases:
 3) should refuse incorrect passphrases
Transaction functionality
4) "before all" hook
✖ 4 of 24 tests failed:
@kenmanheimer
kenmanheimer / gist:6717139
Created September 26, 2013 17:03
problem bootstrapping crypton, on 'sharing' branch
crisp.crypton 2: git branch
master
* sharing
crisp.crypton 3: ls
.git/ Makefile integration_tests/
.gitignore README.md otis.config.js
.travis.yml client/ server/
LICENSE doc/
crisp.crypton 4: make
make -C server test