Skip to content

Instantly share code, notes, and snippets.

View fed's full-sized avatar

fed

View GitHub Profile
@fed
fed / package.json
Last active November 22, 2017 15:39
Sending emails with Express.js and Node.js
{
"name": "serverify",
"version": "0.0.0",
"description": "Simple web server powered by Node.js, Express.js and Nodemailer",
"main": "server.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
@fed
fed / ssr.js
Last active August 31, 2017 20:23
Isomorphic JavaScript Server Logic Example
/*
* Rendering our component server side
*/
var React = require('react');
var App = require('../lib/components/todo-item');
var data = { title: 'Hello world!' };
var renderedComponent = ReactDOMServer.renderToString(<App data={data} />);
@fed
fed / fibonacci.js
Last active August 22, 2017 17:21
Fibonacci with Memoization
// Time complexity: O(n)
// Space complexity: O(n)
const memo = new Map();
function fibonacci(n) {
if (memo.has(n)) {
return memo.get(n);
}
@fed
fed / observer.js
Created August 22, 2017 17:44
Simple observer pattern implementation
function Counter() {
this.count = 0;
this.observers = [];
}
Counter.prototype.increment = function () {
this.count++;
this.notify({ count: this.count });
};
@fed
fed / linked-list.js
Last active August 22, 2017 18:48
Singly-linked lists implementation
function Node(data) {
this.data = data;
this.next = null
}
function LinkedList() {
this.head = null;
this.length = 0;
}
@fed
fed / factorial.js
Created August 31, 2017 20:46
Factorial
// Recursively
// From `n`, all the way down to 1
function factorial(n) {
if (n < 2) {
return 1;
}
return n * factorial(n - 1);
}
@fed
fed / bubble-sort.js
Created August 31, 2017 22:17
Bubble Sort
const numbers = [13, 5, -3, 7, 6, 4, 1, 17, 0, -1, -2];
function sort(arr) {
const sorted = arr.slice();
let swapped;
do {
swapped = false;
for (let i = 0, l = sorted.length; i < l; i++) {
@fed
fed / README.md
Created September 3, 2019 09:00
Focus Debugging Snippet

Debugging Snippet

This snippet is useful for debugging things like who's setting focus on a particular element.

DevTools > Source tab > Top left panel > Select snippet > New snippet

Disclaimer: this snippet only breaks when <HTMLElement>.focus() is called -- if you want to break on focus events, Safari's debugger lets you set DOM event breakpoints.

@fed
fed / README.md
Last active October 11, 2019 11:06
CSS Specificity

CSS Specificity

When multiple selectors are targeting the same element, the browser needs to know which one to apply. This is where the cascading aspect of CSS and specificity come into play. It's important to understand how specificity is calculated, so that you'll be able to figure out which style will actually end being applied in the browser.

(
  inline styles,
  IDs,
  classes | attributes | pseudo-classes,
  elements | pseudo-elements
@fed
fed / jira-template.md
Created April 15, 2020 01:09
JIRA Ticket Template

Issue / Request

Client context

Priority context

Affected versions

Acceptance criteria