Skip to content

Instantly share code, notes, and snippets.

View themeteorchef's full-sized avatar

The Meteor Chef themeteorchef

View GitHub Profile
@themeteorchef
themeteorchef / get-text-replacement.js
Created August 31, 2016 14:36
Native Node.js File Read in Meteor
/*
Read a file with Node's fs instead of Meteor's Assets lib.
Originally used as a swap for Meteor's Assets.getText() method not working consistently.
*/
import fs from 'fs';
const file = 'some-file-in-private.html';
// assets/app here is analagous to your /private directory in the root of your app. This is where Meteor ultimately
// stores the contents of /private in a built app.
Template.newUser.onRendered( () => {
$("#signUpForm").validate({
highlight: function(element, errorClass) {
$(element).parent().addClass(errorClass);
},
unhighlight: function(element, errorClass, validClass) {
$(element).parent().removeClass(errorClass).addClass(validClass);
},
onfocusout: true,
errorClass: "has-error",
@themeteorchef
themeteorchef / example-method.js
Created March 1, 2016 14:45
Execute If Allowed
Meteor.methods({
authorizedMethod() {
Modules.server.executeIfAllowed( [ 'admin', 'manager' ], () => {
// Some secure task to complete here.
});
}
});
@themeteorchef
themeteorchef / roles.js
Created January 22, 2016 21:15
Roles Example
Companies = new Meteor.Collection();
{
"Company 1": {
_id: "companyOne",
roles: [
'bacon',
'eggs',
'biscuits'
]
@themeteorchef
themeteorchef / format.js
Created January 22, 2016 14:47
RFC-822 formatting for Moment.js
// RFC-822 formatting string for Moment.js.
let timestamp = 'ddd, DD MMM YYYY hh:mm:ss';
// Note, the "z" character responsible for setting the three-character timezone for a date in Moment.js is now deprecated.
// An easy workaround for this is to generate your date/time using the string above, appending the timezone manually.
//
// e.g. return `${ timestamp } CST`;
//
// Here, "CST" would need to be calculated on your own and would likely be a variable unless timezone is fixed.
@themeteorchef
themeteorchef / paginated-publication.js
Created January 21, 2016 02:51
Pagination Experiment
Meteor.publish( 'pagination', function( collection, split, page ) {
check( collection, String );
check( split, Number );
check( page, Match.OneOf( String, Number ) );
var documents = global[ collection ].find( {}, { fields: { _id: 1 } } ).fetch(),
documentChunks = _.chunk( documents, split ),
filter = page ? parseInt( page, 10 ) : 0,
ids = _.map( documentChunks[ filter ], '_id' );
@themeteorchef
themeteorchef / timezones.js
Last active September 12, 2024 13:11
Array of timezones as objects, sorted by offset and name.
[
  {
    "offset": "GMT-12:00",
    "name": "Etc/GMT-12"
  },
  {
    "offset": "GMT-11:00",
    "name": "Etc/GMT-11"
  },
  {
@themeteorchef
themeteorchef / timezones.json
Last active February 19, 2021 09:12
Timezones by UTC Offset
[
{
"value":"International Date Line West",
"name":"(GMT-11:00) International Date Line West"
},
{
"value":"Midway Island",
"name":"(GMT-11:00) Midway Island"
},
{
@themeteorchef
themeteorchef / timezones
Created October 12, 2015 18:01 — forked from ykessler/timezones
JSON list of time zones (Based on Olson tz database)
[
{"group":"US (Common)",
"zones":[
{"value":"America/Puerto_Rico","name":"Puerto Rico (Atlantic)"},
{"value":"America/New_York","name":"New York (Eastern)"},
{"value":"America/Chicago","name":"Chicago (Central)"},
{"value":"America/Denver","name":"Denver (Mountain)"},
{"value":"America/Phoenix","name":"Phoenix (MST)"},
{"value":"America/Los_Angeles","name":"Los Angeles (Pacific)"},
{"value":"America/Anchorage","name":"Anchorage (Alaska)"},
@themeteorchef
themeteorchef / Javascript ISO country code to country name conversion
Created October 5, 2015 20:16 — forked from maephisto/Javascript ISO country code to country name conversion
ISO 3166-1 alpha-2 country code to country name conversion with a simple Javascript implementation, an array and a function.
var isoCountries = {
'AF' : 'Afghanistan',
'AX' : 'Aland Islands',
'AL' : 'Albania',
'DZ' : 'Algeria',
'AS' : 'American Samoa',
'AD' : 'Andorra',
'AO' : 'Angola',
'AI' : 'Anguilla',
'AQ' : 'Antarctica',