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:bcbf37058d7ee22a054a
Last active August 29, 2015 14:15
Keybase proof
### Keybase proof
I hereby claim:
* I am KevinSjoberg on github.
* I am kevinsjoberg (https://keybase.io/kevinsjoberg) on keybase.
* I have a public key whose fingerprint is 36EF 02EC 5C01 6E8B 204C 3DF9 545F F40D 7393 07FC
To claim this, I am signing this object:
def parse(filename)
contents = File.read(filename)
[contents.gsub("\n", "").split(//), contents.split[0].size]
end
def neighbours(i, s)
f,l=[i%s==0,i%s==s-1]
[(f ? -1 : i-s-1),i-s,(l ? -1 : i-s+1),(f ? -1 : i-1),(l ? -1 : i+1),(f ? -1 : i+s-1),i+s,(l ? -1 : i+s+1) ].reject { |i| i < 0 }
end
@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)
#!/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