Skip to content

Instantly share code, notes, and snippets.

@iDVB
iDVB / serverless.yml
Created March 1, 2018 04:33
WAF Rules
Resources:
WebACL:
Type: "AWS::WAF::WebACL"
Properties:
DefaultAction:
Type: BLOCK
MetricName: "TrustedIPs"
Name: "TrustedIPs"
Rules:
- Action:
@philmerrell
philmerrell / audio.service.ts
Created November 20, 2017 21:10
Angular audio service class
import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs/Rx';
@Injectable()
export class AudioService {
public audio: HTMLAudioElement;
public timeElapsed: BehaviorSubject<string> = new BehaviorSubject('00:00');
public timeRemaining: BehaviorSubject<string> = new BehaviorSubject('-00:00');
public percentElapsed: BehaviorSubject<number> = new BehaviorSubject(0);
@slavafomin
slavafomin / 0-README.md
Last active March 15, 2023 13:35
Angular 2 match other field validator / Password match validator

Angular 2 match other field validator

This custom validator for Angular 4 allows you to have fields that must be equal to some other fields. Such validator is very useful for password confirmation validation, for example.

Besides checking if two values are matching, it also subscribes to changes from other control and re-validates when either of two controls is updated.

Usage

@carcinocron
carcinocron / debugger pause beforeunload
Last active July 10, 2024 08:48
Chrome: pause before redirect
// Run this in the F12 javascript console in chrome
// if a redirect happens, the page will pause
// this helps because chrome's network tab's
// "preserve log" seems to technically preserve the log
// but you can't actually LOOK at it...
// also the "replay xhr" feature does not work after reload
// even if you "preserve log".
window.addEventListener("beforeunload", function() { debugger; }, false)
@justmoon
justmoon / custom-error.js
Last active June 26, 2024 09:36 — forked from subfuzion/error.md
Creating custom Error classes in Node.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
Instance.db.User = Instance.db.sequelize.define('user', {
email: {
type: Sequelize.STRING,
allowNull: false,
validate: {
isEmail: true
}
},
password: {
type: Sequelize.STRING,
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active July 2, 2024 00:02
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@ryelle
ryelle / admin-icon.php
Created December 3, 2013 16:56
Set up a fake menu item to test using an icon font.
<?php
/**
* Plugin Name: Admin Icon Example
*/
// Add the fake menu item
add_action( 'admin_menu', 'admin_fake_menu_item' );
function admin_fake_menu_item() {
add_menu_page( 'Icon Test', 'Icon Test', 'edit_posts', 'admin-icon-font', '__return_true' );
}
@erikflowers
erikflowers / css text select highlight
Created September 26, 2013 05:57
CSS Text Select Highlight
// This is the mixin
.highlight(@backgroundColor, @textColor) {
::selection, -moz::selection {
background: @backgroundColor;
color: @textColor;
}
}
// This is how you use it
@cerebrl
cerebrl / 1-securing-express.md
Last active August 2, 2023 22:48
Securing ExpressJS

tl;dr

  1. Don't run as root.
  2. For sessions, set httpOnly (and secure to true if running over SSL) when setting cookies.
  3. Use the Helmet for secure headers: https://github.com/evilpacket/helmet
  4. Enable csrf for preventing Cross-Site Request Forgery: http://expressjs.com/api.html#csrf
  5. Don't use the deprecated bodyParser() and only use multipart explicitly. To avoid multiparts vulnerability to 'temp file' bloat, use the defer property and pipe() the multipart upload stream to the intended destination.