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: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
# After running substitute(a:msg, '\e\[[0-9;]\+[mK]', '', 'g')
-- SYNTAX PROBLEM - /var/folders/rc/yr76zbp97nn03xncbwbx05jw0000gn/T/nvimmBWCb7/1.elm^@^@I ran into something unexpected when parsing your code!^@^@8│ main = |^@ ^^@I am looking for one of the following things:^@^@ an expression^@ whitespace^@^@^@Processing file /var/folders/rc/yr76zbp97nn03xncbwbx05jw
0000gn/T/nvimmBWCb7/1.elm^@ERRORS
@hovsater
hovsater / .git.bash
Created April 21, 2017 14:56
Complete git branch with fzf
# Put this in ~/.git.bash
# Then in ~/.bashrc just execute the following: [ -f ~/.git.bash ] && . ~/.git.bash
__fzf__git_branch__() {
local branches branch
git rev-parse HEAD > /dev/null 2>&1 &&
branches=$(git branch -a -vv --color=never | grep -v '/HEAD\s') &&
echo "$branches" | fzf --height 40% --tac | sed 's/^..//' | awk '{print $1}' | sed 's#^remotes/[^/]*/##'
}
bind '"\C-g\C-b": "$(__fzf__git_branch__)\e\C-e\er"'
describe 'date_range_time_period_critera' do
date_range_query = { }
stub_date_range_critera date_range_query
time_period_query = { }
stub_time_period_critera time_period_query
described_class.build(params)
expect(query_builder[:query][:bool][:must]).to include(
hash_including(bool: { should: date_range_query[:bool][:must] << time_period_query })
{
"users": {
"1": { "nickname": "John" },
"2": { "nickname": "Jane" }
},
"posts": {
"1": { "title": "Greg is awesome!", "user_id": "1" },
"2": { "title": "Twitch is fun!", "user_id": "1" },
"3": { "title": "I'm a tool.", "user_id": "2" }
class ResourceResponse
delegate status_code, status_message, to: @http_client_response
@http_client_response : HTTP::Client::Response
def initialize(@http_client_response, @serializable)
end
def resource
@serializable.from_json(@http_client_response.body)
module Fortnox
class ResourceResponse(T)
delegate status_code, status_message, success?, to: @http_client_response
@http_client_response : HTTP::Client::Response
def initialize(@http_client_response)
end
def resource
require "json"
module Fortnox::Response
struct CompanySettings
include JSON::Serializable
@[JSON::Field(key: "CompanySettings")]
property company_settings : Resource::CompanySettings
def self.from_response(response : HTTP::Client::Response) : self

Armstrong Numbers

An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.

For example:

  • 9 is an Armstrong number, because 9 = 9^1 = 9
  • 10 is not an Armstrong number, because 10 != 1^2 + 0^2 = 1
  • 153 is an Armstrong number, because: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
  • 154 is not an Armstrong number, because: 154 != 1^3 + 5^3 + 4^3 = 1 + 125 + 64 = 190
[shim]: Set up Shim to run with the following parameters:
path to executable: C:\ProgramData\chocolatey\lib\unison\tools\unison 2.48.4 text.exe
working directory: C:\ProgramData\chocolatey\bin
is gui? False
wait for exit? True
command (optional):
[shim]: Command line '"unison 2.48.4 text.exe" --shimgen-log'
[shim]: Current process '"C:\ProgramData\chocolatey\bin\unison 2.48.4 text.exe"'
[shim]: Command line after removing process '"unison 2.48.4 text.exe" --shimgen-log'
[shim]: Shifting off the first argument since process didn't catch it