Skip to content

Instantly share code, notes, and snippets.

View themeteorchef's full-sized avatar

The Meteor Chef themeteorchef

View GitHub Profile
@themeteorchef
themeteorchef / multiplex.js
Created October 4, 2015 19:17
Multiplex in CodeMirror
// Taken from the source of the demo here: https://codemirror.net/demo/multiplex.html
CodeMirror.defineMode("demo", function(config) {
return CodeMirror.multiplexingMode(
CodeMirror.getMode(config, "text/html"),
{open: "<<", close: ">>",
mode: CodeMirror.getMode(config, "text/plain"),
delimStyle: "delimit"}
// .. more multiplexed styles can follow here
);
@themeteorchef
themeteorchef / home.html
Created October 4, 2015 19:29
Using the HTML5 download attribute
<template name="home">
<p>File content: {{content}}</p>
<p><a href="{{pathFor 'server.file'}}" download="filename.type">Download a file</a></p>
</template>
@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',
@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 / 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.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 / 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 / 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 / roles.js
Created January 22, 2016 21:15
Roles Example
Companies = new Meteor.Collection();
{
"Company 1": {
_id: "companyOne",
roles: [
'bacon',
'eggs',
'biscuits'
]
@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.
});
}
});