Skip to content

Instantly share code, notes, and snippets.

@msroot
msroot / token-generator.js
Created December 2, 2021 23:47 — forked from ziluvatar/token-generator.js
Example of refreshing tokens with jwt
/**
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken
* It was requested to be introduced at as part of the jsonwebtoken library,
* since we feel it does not add too much value but it will add code to mantain
* we won't include it.
*
* I create this gist just to help those who want to auto-refresh JWTs.
*/
const jwt = require('jsonwebtoken');

Automate Deploy Node App in Amazon EC2 Linux

PREREQUISITES

To Login

ssh -i <private-key-file/pem> ec2-user@[ec2-hostname].amazonaws.com
  1. Install Node JS & pm2 Ref:
@msroot
msroot / to_I18n.rb
Created July 13, 2021 23:05
ActiveRecord to to_I18n
locale = {
en: {
activerecord: {
models: {},
attributes: {}
}
}
}
exclude = [
const generateHash = require('object-hash')
const randomColor = require('randomcolor')
const similarity = {}
const uniqRandomColor = (options = {}) => {
let color = randomColor(options)
while (Object.values(similarity).includes(color)) {
color = randomColor(options)
}
@msroot
msroot / graphql_introspection_query.graphql
Created June 2, 2021 10:27 — forked from a7v8x/graphql_introspection_query.graphql
GraphQL introspection query - for fetching the whole schema (from GraphiQL IDE) for https://atheros.ai/blog/graphql-introspection-and-introspection-queries
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
types {
...FullType
}
directives {
name
description
@msroot
msroot / 00-intro.md
Created March 23, 2021 23:51 — forked from mdo/00-intro.md
Instructions for how to affix an Ikea Gerton table top to the Ikea Bekant sit-stand desk frame.

Ikea Bekant standing desk with Gerton table top

@msroot
msroot / hasMany.js
Last active March 3, 2021 14:43
mongoose hasMany plugin
//dbPlugins.js
import mongoose from 'mongoose'
export const hasMany = (schema, options) => {
for (const [className, finder] of Object.entries(options)) {
const plural = schema.base._pluralize(className)
schema.methods[plural] = function (cb) {
for (const [k, v] of Object.entries(finder)) {
finder[k] = v.toString()[0] === '$' ? this.get(v.replace('$', '')) : v
}
const { ApolloServer, gql } = require('apollo-server')
const { RESTDataSource } = require('apollo-datasource-rest')
class CountriesAPI extends RESTDataSource {
constructor() {
super()
this.baseURL = 'https://restcountries.eu/rest/v2'
}
async getAllCountries() {
return this.get('/all')
require 'git'
g = Git.open('./')
g.branch('staging').checkout
report = []
log = g.log(900000000)
log.each {|commit|
next unless commit.commit?
e = commit.date
@msroot
msroot / monetize.rake
Last active April 29, 2020 12:04
Check if all monetize attributes set
# rake monetize:verify
namespace :monetize do
desc "Verifies if all monetize attributes are set"
task verify: :environment do
ActiveRecord::Base.connection.tables.sort.map do |model|
next if %w(schema_migrations ar_internal_metadata versions).include?(model)
puts "Scanning: #{model}"