Skip to content

Instantly share code, notes, and snippets.

View jeffkreeftmeijer's full-sized avatar
🦞

Jeff Kreeftmeijer jeffkreeftmeijer

🦞
View GitHub Profile
@jeffkreeftmeijer
jeffkreeftmeijer / 1.png
Last active November 3, 2023 00:56
Ruby image diff
1.png
" Vim color scheme
"
" Name: railscat.vim
" Maintainer: Jeff Kreeftmeijer
" License: public domain
"
" A GUI only extended version of the Railscasts+ theme, that comes with
" Janus [1] and is, in turn, an extension to the original Railscasts theme
" [2], which is a port of the RailsCasts TextMate theme [3] to Vim.
"
@jeffkreeftmeijer
jeffkreeftmeijer / 1.png
Created April 18, 2011 08:34
Image difference blend
1.png
@jeffkreeftmeijer
jeffkreeftmeijer / 1.png
Created April 18, 2011 12:39
Delta-E image diff
1.png
require 'socket'
require 'rack'
require 'rack/lobster'
app = Rack::Lobster.new
server = TCPServer.new 5678
while session = server.accept
request = session.gets
puts request
@jeffkreeftmeijer
jeffkreeftmeijer / job.rb
Last active August 6, 2021 19:44
job.rb
loop do
retries = 0
begin
# TODO fetch and run a job
rescue StandardError => error
if retries < 10
sleep(retries * 10)
retries += 1
@jeffkreeftmeijer
jeffkreeftmeijer / XmlParser.h
Created March 15, 2012 11:24
Objective-C XML parser
#import <Foundation/Foundation.h>
@interface XmlParser : NSObject <NSXMLParserDelegate>
@property (strong, nonatomic) NSData *xmlData;
@property (strong, nonatomic) NSMutableDictionary *dictionary;
@property (strong, nonatomic) NSMutableDictionary *currentNode;
@property (strong, nonatomic) NSMutableDictionary *currentParentNode;
- (id)initWithXMLData:(NSData *)xmlData;
Gem::Specification.new do |s|
s.name = 'bang'
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.author = 'Jeff Kreeftmeijer'
s.email = 'jeff@kreeftmeijer.nl'
s.summary = 'Bang!'
s.description = 'Bangs existing model methods'
s.files = ['bang.rb']

Subshells

A subshell creates a separate instance of the command processor, or a subprocess of the parent shell. Although a subshell is started in its parent’s working directory, directory changes made within the subshell don’t carry over to its parent. This makes subshells ideal for running one-off commands in a different directory:

$ pwd
/Users/jeffkreeftmeijer/rust/conway/
$ (cd www && npm install)
[...]
$ pwd
/Users/jeffkreeftmeijer/rust/conway/

Vim Macros

To record a macro, press q in normal mode, followed by a paste registry to store the macro in. To define a quick macro to use a couple of times, I usually use the q registry, meaning I type qq. Vim will tell you you’re currently recording a macro in the status line.

--recording @q

Vim will now record your commands to be used later. For example, to convert a markdown-style link ([Jeff Kreeftmeijer](https://jeffkreeftmeijer.com)) to an asciidoc-style one (Jeff Kreeftmeijer) one, the recorded macro looks like this [1]:

f(di(F[Pa:^[f(xx

1. A subsitution might be a better fit for this specific case