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
# 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