Skip to content

Instantly share code, notes, and snippets.

View nilsandrey's full-sized avatar
🏠

Nils nilsandrey

🏠
View GitHub Profile

Enable

  • Enable Hyper-V:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
  • Reboot.
// <https://dev.to/jorik/country-code-to-flag-emoji-a21>
function getFlagEmoji(countryCode) {
const codePoints = countryCode
.toUpperCase()
.split('')
.map(char => 127397 + char.charCodeAt());
return String.fromCodePoint(...codePoints);
}
const array = [1, 2, 3, 4, 5];
array.groupBy((num, index, array) => {
return num % 2 === 0 ? 'even': 'odd';
});
// => { odd: [1, 3, 5], even: [2, 4] }>
const odd = { odd: true };
const even = { even: true };
@nilsandrey
nilsandrey / get_org_invoices_this_year.rb
Created December 6, 2021 16:59
Stripe request for invoices of this year for one customer
org = Organization.find(…) # <- Whatever magic do you use...
require 'stripe'
hackertime = Date.new(2021,11,1).to_time.to_i # <- It's just unix time, but it's the name front end guys do
Stripe.api_key = org.stripe_api_key # <- Your model should rock this way (auto region switch you known)
invoices = Stripe::Invoice.list({ "customer": org.stripe_customer_key, "created": { "gte": hackertime }})

You can clone the wiki of your github project via ssh:

git clone git@github.com:YOUR_USERNAME/YOUR_REPOSITORY.wiki.git
@nilsandrey
nilsandrey / seeds.rb
Created December 5, 2021 15:58
Load Rails db seeds from test fixtures
# From:
# https://www.danott.co/posts/seeding-development-with-test-fixtures/
def load_fixtures
Rake::Task["db:fixtures:load"].invoke
end
load_fixtures
@nilsandrey
nilsandrey / time_diff_in_words.rb
Last active November 25, 2021 00:28
Minimal wrapping to `time_ago_in_words` to add "ago" for past times or prepend "in" for future.
##
# Minimal adjustment to time_ago_in_words to add "ago" for past times or prepend "in" for future.
#
# Sample output: "in 8 days / in about 24 hours / 11 days ago"
#
def time_diff_in_words(date)
return '' unless date
words = time_ago_in_words(date)
return "#{words} ago" if date < Date.today
@nilsandrey
nilsandrey / filterable.rb
Last active November 5, 2021 21:25
Search and Filter Rails Models with parameters received by your controllers. Code from @justinweiss.
##
# Search and Filter Rails Models Without Bloating Your Controller
# <https://www.justinweiss.com/articles/search-and-filter-rails-models-without-bloating-your-controller/>
#
# == Usage:
#
# In a model like `app/models/product.rb`:
# ```
# class Product
# include Filterable
@nilsandrey
nilsandrey / qsParam.js
Created October 26, 2021 06:02
Return the value of an expected query string parameter. Return `null` if not present.
export function qsParam(name) {
return new URLSearchParams(document.location.search).get(name);
}
@nilsandrey
nilsandrey / to-gb.pipe.ts
Created September 16, 2021 12:57
to-gb.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'toGb'
})
export class ToGbPipe implements PipeTransform {
transform(value: number, args?: any): string {
return (value / 1073741824).toFixed(2).toString();
}
}