Skip to content

Instantly share code, notes, and snippets.

View hovsater's full-sized avatar
🤟

Kevin Hovsäter hovsater

🤟
View GitHub Profile
@hovsater
hovsater / gist:3048229
Created July 4, 2012 16:39
Books people recommended to me for learning C
@hovsater
hovsater / gist:3818527
Created October 2, 2012 12:09
Problem Solving Challenge #1

Problem Solving Challenge #1

Problem solving challenges are fun. They make use of one's problem solving skills and stimulate the programmer's need to challenge themselves.

Here we go

These 1151159511610110199114 numbers represent a word.

  • The word may only contain a-zA-Z_
  • The word is of size 8.

In this particular case the secret word was s_ecrets.

@hovsater
hovsater / gist:4072890
Created November 14, 2012 15:47
Populate/Repopulate Alfreds text field
# I have seen several requests from developers trying to populate/repopulate
# Alfreds text field with another value. While this is not a native solution,
# it's still suffice quite well.
#
# Explaination
#
# In order to get access to Alfreds windows, it must be toggled. We can achieve
# that by triggering the hotkey specified for Alfred. When toggled, it's as easy
# as just setting a new value for the first text field of window 1.
#
@hovsater
hovsater / gist:4984060
Last active December 13, 2015 22:19
Regular expressions with RubyGems

Very often, I want to check the latest version of a particular gem on RubyGems.org.

This can be accomplished by doing gem list -r GEM_NAME.

Unfortunatley, this doesn't always work out well. If I would run gem list -r capistrano to get the latest version of Capistrano, the list of matches would be quite large.

....
capistrano-zen (0.0.2)
capistrano_auto_multi_install (1.0.6)

capistrano_banner (0.0.4)

@hovsater
hovsater / gist:5003408
Last active December 14, 2015 01:08
Finding processes with pgrep

Ever so often I want to find a particular process on the system. I've always accomplished this by doing ps -ef | grep PROCESS_NAME.

Today, I stumpled upon a new command by coincidence. The pgrep command. By spending a few minutes reading its documentation (man pgrep) I realized what it's capable of.

Run pgrep -i PROCESS_NAME to find processes. The -i flag tells pgrep to perform case insensitive matching.

Run pgrep -ilf PROCESS_NAME to get long output, including the argument list of the matching process.

From now, this is what I'll be using.

@hovsater
hovsater / gist:5039267
Created February 26, 2013 15:25
ssh-config thoughts

SSH Config thoughts

This is some of my thoughts scrambled down in no particular order.

  • Establish a solid test suite for current functionality
  • Retrieve a SSH config by URL and place it under ~/.ssh/ with proper permissions
  • Check the ability to integrate with Transmit.app (FTP Client). Transmit read everything inside ~/.ssh/config but you've to add it as a favorite yourself. I would want to automate that process so that ssh-config set and ssh-config unset add and remove a Trasmit favorite automatically.
  • Update codebase for Ruby 1.9+
  • Merge standanlone commands
  • Add a more configurable interface (colors for highlighting, logging, etc)
@hovsater
hovsater / gist:5068370
Last active October 21, 2021 08:58
Removing non-empty local directories with netrw

A few months ago I read Drew Neil's article about split windows and the project drawer. It's a great article and I strongly recommend you to go ahead and read it.

The article got me spending some time with netrw and sure enough, it replaced NERDTree. One thing that annoyed me though, was its default for deleting directories. Quoting from :help netrw-delete.

Deleting/removing files and directories involves moving the cursor to the file/directory to be deleted and pressing "D". Directories must be empty first before they can be successfully removed.

This is not a default I'm happy with, but as with everything else in Vim, netrw is customisable. The default command for deleting local directories is rmdir which requires the directory to be empty. By setting `g:netrw_localrmdir

#!/bin/sh
VIM_BUNDLE_DIRECTORY=$HOME/.vim/bundle
for dir in $(find $VIM_BUNDLE_DIRECTORY -mindepth 1 -maxdepth 1 -type d); do
cd $dir && echo "Updating $(basename $PWD)..." && git pull
done
@hovsater
hovsater / gist:6213677
Last active December 20, 2015 23:38
Seeda (Design concept)
Seeda.definitions do
# A simple seed
seed { Category.create! name: "Example Category" }
# Seeds can be defined in groups
define :users do
# Seeds can be named for later reference
seed(:john) { User.create! name: "John Doe" }
seed(:jane) { User.create! name: "Jane Doe" }
end
@hovsater
hovsater / gist:7688474
Last active December 29, 2015 15:09
User-defined command to setup key mappings for RSpec.
function RSpecCommands(bang)
if !a:bang
noremap <Leader>t :!bundle exec rspec %<CR>
noremap <Leader>T :!bundle exec rspec %:<C-R>=line('.')<CR><CR>
else
silent! nunmap <Leader>t
silent! nunmap <Leader>T
endif
endfunction