Skip to content

Instantly share code, notes, and snippets.

@RuolinZheng08
RuolinZheng08 / backtracking_template.py
Last active June 6, 2024 22:47
[Algo] Backtracking Template & N-Queens Solution
def is_valid_state(state):
# check if it is a valid solution
return True
def get_candidates(state):
return []
def search(state, solutions):
if is_valid_state(state):
solutions.append(state.copy())
@angle943
angle943 / heaps-algorithm.js
Created February 8, 2020 10:29
Heap's Algorithm In Javascript
const getPermutations = arr => {
const output = [];
const swapInPlace = (arrToSwap, indexA, indexB) => {
const temp = arrToSwap[indexA];
arrToSwap[indexA] = arrToSwap[indexB];
arrToSwap[indexB] = temp;
};
@mehulmpt
mehulmpt / index.js
Last active April 22, 2022 13:14
Slow Loris attack using Node
const net = require('net')
const opts = {
host: 'localhost',
port: 1234,
sockets: 2000,
respawn: false,
rate: 600,
method: 'GET',
path: '/'
@jeffposnick
jeffposnick / service-worker.js
Created September 20, 2019 00:56
Example of InjectManifest in Workbox v5
// Add any other logic here as needed.
import { CacheableResponsePlugin } from 'workbox-cacheable-response/CacheableResponsePlugin';
import { CacheFirst } from 'workbox-strategies/CacheFirst';
import { createHandlerForURL } from 'workbox-precaching/createHandlerForURL';
import { ExpirationPlugin } from 'workbox-expiration/ExpirationPlugin';
import { NavigationRoute } from 'workbox-routing/NavigationRoute';
import { precacheAndRoute } from 'workbox-precaching/precacheAndRoute';
import { registerRoute } from 'workbox-routing/registerRoute';
@jdbdnz
jdbdnz / fontforge-limit-glyphs.py
Last active November 3, 2020 10:24
Limit FontAwesome to just those Glyphs I want to use
# Open font in [fontforge](https://fontforge.github.io/en-US/) (FontAwesome's [fa-solid-900.woff](https://github.com/FortAwesome/Font-Awesome/blob/master/webfonts/fa-solid-900.woff) in my case)
# So you can see what you're doing: Menu > Encoding > Compact
# ctrl+a to select all glyphs
# ctrl+. should open Execute Script
# Ensure desiredGlyphNames includes all glyphs used in app
desiredGlyphNames = ["caret-down", "caret-up", "chart-bar", "check", "chevron-down", "clipboard-list", "comments", "expand", "filter", "flask", "images", "info-circle", "layer-group", "redo", "ruler", "ruler-horizontal", "ruler-vertical", "sort-amount-down", "star", "table", "tag", "users", "video"]
font = fontforge.activeFont()
@timurcatakli
timurcatakli / webpack.config.js
Last active May 1, 2023 18:25
An Easy to Understand Webpack 4+ Configuration File with Comments
const publicPath = 'public';
// Node os module
// The os module provides a number of operating system-related utility methods.
// It can be accessed using:
const os = require('os');
// Using a single monolithic configuration file impacts comprehension and
// removes any potential for reusability.
// As the needs of your project grow, you have to figure out the means to manage
// webpack configuration more effectively.
@jigewxy
jigewxy / child.js
Created February 9, 2018 09:54
node.js fork example --> parent/child process increment and interchange the count variable until >100
var count =Math.floor(Math.random()*100);
process.on('message', (msg)=>{
console.log("CHILD: message received from parent process", msg);
count = parseInt(msg) +1;
console.log("CHILD: +1 from child");
@jaytaylor
jaytaylor / react-unexpected-use-of-location.md
Created July 12, 2017 22:44
Solution for "Unexpected use of 'location'" React error.
React: Unexpected use of 'location';

Solution: Use window.location instead of bare location.

@gustavlrsn
gustavlrsn / Layout.js
Created May 1, 2017 18:11
Example bootstrap 4 integration into Next.js, with the reactstrap package
import Head from 'next/head'
import { Container } from 'reactstrap'
const Layout = (props) => (
<div>
<Head>
<title>PairHub</title>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
</Head>
// Logs all calls to preventDefault / stopPropagation in an user-friendly way
if ( process.env.NODE_ENV !== "production" ) {
(function monkeyPatchEventMethods() {
const logEventMethodCall = (event,methodName) => {
const MinimumMeaninfulSelectors = 3; // how much meaningful items we want in log message
const target = event.target;
const selector = (function computeSelector() {