Skip to content

Instantly share code, notes, and snippets.

@jeremyevans6
jeremyevans6 / timezones.js
Created September 24, 2020 03:13
Time Zones for ShareTribe v10
//This file lives in app/assets/javascripts/
//It has to be required in app/assets/javascripts/application.js, not shown here
//
//It uses browser timezones to correct the client's display of dates and times in three areas of a Sharetribe site.
//By not changing the database, these times will always be UTC in the backend. Indeed, their values remain UTC for the client,
//though the display of the times in the DOM is modified.
const timeRegex = /((1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm]))/g;
const daysOfWeekRegex = /(Sun|Mon|Tue|Wed|Thu|Fri|Sat)/g;
@sohamkamani
sohamkamani / rsa.js
Last active July 4, 2024 13:04
An example of RSA Encryption implemented in Node.js
const crypto = require("crypto")
// The `generateKeyPairSync` method accepts two arguments:
// 1. The type ok keys we want, which in this case is "rsa"
// 2. An object with the properties of the key
const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", {
// The standard secure default length for RSA keys is 2048 bits
modulusLength: 2048,
})
@mkjiau
mkjiau / axios-interceptors-refresh-token.js
Last active March 13, 2024 10:59
Axios interceptors for token refreshing and more than 2 async requests available
let isRefreshing = false;
let refreshSubscribers = [];
const instance = axios.create({
baseURL: Config.API_URL,
});
instance.interceptors.response.use(response => {
return response;
}, error => {
@duksis
duksis / delayed_job.rake
Created February 21, 2012 08:08
Monitor delayed_job processes.
namespace :jobs do
#bundle exec rake delayed_job:monit RAILS_ENV=demo
desc "Monitor delayed_job processes."
task :monit => :environment do
@server_name = `uname -n`.split("\n").first
@application_name = Rails.application.class.parent_name
delayed_job_found = Hash.new
def do_alert(msg)