Skip to content

Instantly share code, notes, and snippets.

View benvds's full-sized avatar
😀

Ben van de Sande benvds

😀
View GitHub Profile
[
{
"name":"Afghanistan",
"code":"AF"
},
{
"name":"Åland Islands",
"code":"AX"
},
{
-- Based on:
--
-- - https://github.com/mjlbach/defaults.nvim
-- - https://github.com/shift-d/nv/
-- - https://github.com/NvChad/NvChad
-- Sane defaults
@benvds
benvds / array_ordering.rb
Last active June 14, 2017 10:26
Move an array item to specified index
module ArrayOrdering
# Returns clone of the array with subject moved into the new idx
def self.move_to_position(_list, subject, new_idx)
old_idx = _list.index(subject)
return _list unless old_idx != new_idx
list = _list.clone
if old_idx.nil?
/**
* Returns a number from a given string. It ignores any characters, including
* comma's and points. When more than 1 number is found in a string, the last
* number is used as the fractional of the number. For example:
*
* '€ 12,34' => 12.34
* '1,234.567 %' => 1234.567
*
* @argument {string} text - text containing the number or number parts
* @returns {number|undefined} - parsed number or undefined when none found
// rotate an array
const rotate = (amount, list) => {
const offset = -(amount % list.length);
return list.slice(offset).concat(list.slice(0, offset));
};

Kalender – Technical considerations

These are some technical considerations for the Kalender component. It returns a calendar matrix containing day objects for a given month. It's implementation is an experiment in writing a Javascript component in a functional style.

When starting I keep things in one file even when there are multiple modules in it. No need to split things up until the it grows to about 150 lines. After 150 lines it gets harder to keep clarity and concepts need to be separated, named and have it's own place.

At the start of the project I mindlessly added lodash, thinking I'd be really needing helper functions like reduce and contains. Turned out I'd could do without. This makes a big difference dependency wise, the library now only has dependencies for building and testing but none are required to get things running.

Removing reduce and contains forced me to think about data structures a bit more. I like objects as data struc

Creating a Javascript component – reasons & requirements

Recently I've created javascript calendar component called Kalender. What the hell was I thinking in creating yet another javascript calendar?

Reasons

Javascript has a lot of frameworks and libraries. Sadly a lot of them are not up to my personal standards. This is probably because about every developer seems to be writing Javascript. This includes junior developers and developers who mainly use another language and bend their style only enough to get things working. Besides that front-end development is a rapidly changing environment with browsers, frameworks and requirements changing fast, what used to be best practice is now frowned upon.

Most of my professional time is spent working on client projects. Clients expect me to deliver business value as effectively as possible which often means writing code that is good enough and using existing libraries, even if these libraries are not what I'd like them to

@benvds
benvds / guide-ror-on-ubuntu.md
Last active August 29, 2015 14:03
Step by step guide to installing a Ruby on Rails application on Ubuntu

Step by step guide to installing a Ruby on Rails application on Ubuntu

This guide aims to get you started running a basic Ruby on Rails application on Ubuntu. It can be used for web applications with small usage and provides a cheap alternative, e.g. €5 a month on Digital Ocean, to services like Heroku which cost much more because of expensive add-ons. The setup includes:

  • support for just a single Ruby on Rails web application
  • database support (PostgreSQL)
  • email support (sendmail)
  • background job support
  • multiple application processes (Unicorn)
  • front-end http server with asset caching (Nginx)
/* global jQuery */
;(function(window, $) {
'use strict';
var firstPrivate = 1,
secondPrivate = '2',
defaults = {
'firstOption': false,
'secondOption': 5000
@benvds
benvds / test_rest_api.rb
Last active December 21, 2015 04:19
use of basic auth disables before block
require 'sinatra/base'
class TestRestApi < Sinatra::Base
before do
headers['Access-Control-Allow-Origin'] = '*'
content_type :json
end
# no more header & content_type when to following is enabled