Skip to content

Instantly share code, notes, and snippets.

View jmcantrell's full-sized avatar
🤖
Creating new neural pathways.

Jeremy Cantrell jmcantrell

🤖
Creating new neural pathways.
View GitHub Profile
@senko
senko / maybe.py
Last active May 2, 2024 18:35
A Pythonic implementation of the Maybe monad
# maybe.py - a Pythonic implementation of the Maybe monad
# Copyright (C) 2014. Senko Rasic <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
@branneman
branneman / better-nodejs-require-paths.md
Last active May 15, 2025 11:17
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

anonymous
anonymous / gist:5906387
Created July 2, 2013 02:32
def add_concurrent_options(parser, prefer_threads=False):
# Adds relevant options to parser
parser.add_argument("--workers", choices=("threads", "processes"), default="threads" if prefer_threads else "processes",
help="Select if concurrency is done using threads or processes [%(default)s]")
parser.add_argument("--single", action="store_true", help="Uses a single thread for concurrency. This makes debugging a lot easier")
import multiprocessing
def get_concurrent_executor(options):
# Gets a suitable executor
if options.workers=="threads" or options.single:
@dahu
dahu / gist:4362268
Created December 23, 2012 06:08
valid 'if' forms
" Valid 'if' forms:
if 1 | endif
if 1
endif
if 1 | echo "1" | endif
if 1
echo "2"
@dahu
dahu / gist:4250520
Created December 10, 2012 13:21
Godlygeek's Comment Text Object
" author: godlygeek
" 22 Jun 2010
"
" the objects returned are visual mode commands
" in visual mode, o jumps to the other end of the match
"
function! s:VAC()
if search('\m\%#/\*', 'bcnW') || search('\m/\%#\*', 'bcnW')
" On /*
return ']*o]*[*o'
@dahu
dahu / gist:4137807
Created November 24, 2012 00:18
ftplugin/help.vim
" help.vim - ftplugin for better Help navigation and operation
" Barry Arthur
" jump to links with CR
nmap <buffer> <CR> <C-]>
" jump back with BS
nmap <buffer> <BS> <C-T>
" skip to next option link
nmap <buffer> o /'[a-z]\{2,\}'<CR>
" skip to previous option link
@dahu
dahu / gist:4054442
Created November 11, 2012 10:28
RotateBuffer
function! RotateBuffer()
let rb=[]
for x in range(max(map(getline(1, '$'), 'len(v:val)')))
call add(rb, [])
for y in range(line('$'))
call add(rb[x], ' ')
endfor
endfor
let y = 0
for line in getline(1,'$')
@dahu
dahu / gist:4035975
Created November 8, 2012 01:50
godlygeek's syntax region text object
" author: godlygeek
function s:movement_string(line, col)
return a:line . "G0" . (a:col > 1 ? (a:col - 1) . "l" : "")
endfunction
function! s:VAR()
let group = synID(line('.'), col('.'), 1)
let orig = [ line('.'), col('.') ]
@dahu
dahu / gist:3986511
Last active November 18, 2024 09:34
Vim Motions
Large Object Motions:
(
)
{
}
[[
[]
][
]]
[m
@dahu
dahu / gist:3726230
Created September 15, 2012 03:20
Automatically highlight word under cursor if it appears more than once in the file.
" Clean-up of Swicher's Highlighter()
" Barry Arthur 2012-09-15
function! Highlighter()
let word_cursor = escape(expand('<cword>'), ".*[]\\")
redir => output
silent! execute '%s/\<'.word_cursor.'\>//gen'
redir END
if output != ""
if str2nr(split(output)[0]) > 1