Skip to content

Instantly share code, notes, and snippets.

View nilsandrey's full-sized avatar
🏠

Nils nilsandrey

🏠
View GitHub Profile
@nilsandrey
nilsandrey / node-static-serve.js
Last active May 2, 2024 02:59
NodeJS based directory browsing and file serve without dependencies
// NodeJS based directory browsing and file serve without dependencies
// Joining code from <https://stackoverflow.com/questions/16333790/node-js-quick-file-server-static-files-over-http>
var fs = require("fs"),
http = require("http");
http
.createServer(function (req, res) {
// Website you wish to allow to connect
res.setHeader("Access-Control-Allow-Origin", "*");
@nilsandrey
nilsandrey / String.format.js
Last active May 2, 2024 03:10
string.format in Javascript.
// <https://stackoverflow.com/a/4673436/2100126>
// First, checks if it isn't implemented yet.
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
@nilsandrey
nilsandrey / SendToTypefull-bookmarklet.js
Last active May 2, 2024 03:08
Use this code on a new bookmark to send current page to a new Typefully draft.
javascript:(function(){f='https://typefully.com/?new='+encodeURIComponent(document.title)+'%250A'+encodeURIComponent(window.location.href);a=function(){if(!window.open(f))location.href=f};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()

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 [email protected]: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