Skip to content

Instantly share code, notes, and snippets.

View k9ordon's full-sized avatar
🐙

Klemens Gordon k9ordon

🐙
View GitHub Profile
@Daniel-Hug
Daniel-Hug / delegate-event.js
Last active September 14, 2020 05:05
Vanilla JS equivalent of jQuery's .live(): use event delegation to handle events whose target matches a selector, closest(): get nearest parent element matching selector
// get nearest parent element matching selector
var closest = (function() {
var el = HTMLElement.prototype;
var matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
return function closest(el, selector) {
return matches.call(el, selector) ? el : closest(el.parentElement, selector);
};
})();
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
@Couto
Couto / webpack.js
Last active November 11, 2020 17:53
Fetch polyfill with webpack
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var folders = {
APP: path.resolve(__dirname, '../app'),
BUILD: path.resolve(__dirname, '../build'),
BOWER: path.resolve(__dirname, '../bower_components'),
NPM: path.resolve(__dirname, '../node_modules')
};
@datchley
datchley / es6-eventemitter.js
Last active June 7, 2021 03:40
A straight forward EventEmitter implemented in Javascript using ES6
let isFunction = function(obj) {
return typeof obj == 'function' || false;
};
class EventEmitter {
constructor() {
this.listeners = new Map();
}
addListener(label, callback) {
this.listeners.has(label) || this.listeners.set(label, []);
@mcevskb
mcevskb / trakt-remove-history.js
Last active July 8, 2021 21:07 — forked from hugoboos/trakt-remove-history.js
Remove duplicate episodes from Trakt
// Run in console on the history page (http://trakt.tv/users/<username>/history)
// Will remove all the duplicate episodes, on that page, from the watched history.
var episodesRemoved = []
// episodeItems = $("[data-type=episode]")
episodeItems.each(function(){
var $this = $(this);
var episodeId = $this.data('episode-id')
var showId = $this.data('show-id')
@codingwithchris
codingwithchris / KEYSTONE-JS-ACCESS-CONTROL.MD
Last active March 16, 2022 09:25
Unpacking Keystone JS Access Control (a security-focused perspective)

Access Control (Creating a Secure and Trusted Application)

Access control is critical to the security of our application. Beyond proper credential encryption, hashing, SALTing etc, access control is the next line of defense in protecting our users data.

Role Based Access Control Methodology (RBAC)

When giving elevated access to a User for a particular part of the system, we use a methodology called RBAC. This means that we create Roles where we assign permissions and apply filter policies. These Roles then get assigned to Users who have their CRUD access to Lists, Records, and Fields determined accordingly.

Our Access Control Philosophy

page.includeJs("http://www.google.com/jsapi?key=AIzaSyA5m1Nc8ws2BbmPRwKu5gFradvD_hgq6G0", function() {
page.evaluate(function() {
google.load("feeds", "1");
var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
feed.includeHistoricalEntries(); // tell the API we want to have old entries too
feed.setNumEntries(250); // we want a maximum of 250 entries, if they exist
feed.load();
@TheRealFlyingCoder
TheRealFlyingCoder / .Keystone.js with Docker and Fly.io
Last active January 10, 2023 13:24
Keystone.js with Docker and Fly.io
So once you figure out all the caveats, running Keystone on Docker and in Fly.io is relatively simple.
package.json:
You need --fix on your setup script for Docker to auto update the schemas
"setup": "keystone postinstall --fix"
NOTES FOR DOCKER:
1. I use Yarn V3 in a monorepo hence the corepack lines and project structure
@fwielstra
fwielstra / api.js
Created June 14, 2011 14:46
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@PatrickJS
PatrickJS / factory-shared.es5.js
Last active January 6, 2024 04:18
Different examples of OOP "class" with "inheritance" done using JavaScript including languages that transpile into js. Take notice to the amount of boilerplate that's needed in ES5 compared to ES6. These examples all have the same interface with pros/cons for each pattern. If they seem similar that's whole point especially the difference between…
var EventEmitter = require('events').EventEmitter;
var _ = require('lodash');
// Factory shared
var makePerson = function() {
var person = {};
EventEmitter.call(person);
person.wallet = 0;
_.extend(person, personMethods)
return person;