Skip to content

Instantly share code, notes, and snippets.

@Yimiprod
Yimiprod / difference.js
Last active May 10, 2024 16:49
Deep diff between two object, using lodash
/**
* This code is licensed under the terms of the MIT license
*
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
@domenic
domenic / promises.md
Last active March 31, 2024 14:07
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@impressiver
impressiver / raven-config.html
Last active February 27, 2024 14:27
Raven.js configuration for logging JavaScript exceptions to Sentry (https://getsentry.com/). Without the added ignore options, you'll quickly find yourself swamped with unactionable exceptions due to shoddy browser plugins and 3rd party script errors.
<!-- Raven.js Config -->
<script src="{{ JS_PATH }}/lib/raven.js" type="text/javascript"></script>
<script type="text/javascript">
// Ignore list based off: https://gist.github.com/1878283
var ravenOptions = {
// Will cause a deprecation warning, but the demise of `ignoreErrors` is still under discussion.
// See: https://github.com/getsentry/raven-js/issues/73
ignoreErrors: [
// Random plugins/extensions
'top.GLOBALS',
@ersinakinci
ersinakinci / electron-webpack-node-integration-false.md
Last active January 25, 2023 19:03
Making electron-webpack work with nodeIntegration: false

NOTE, April 18, 2020: I wrote this document in February 2019 when I was actively investigating Electron. I haven't used it since then and have largely forgotten what this was for or how electron-webpack works. I vaguely remember the problem, but that's it. It would appear based on the comments below that this document is still coming up in web searches but has become out of date and parts of it don't work. If anyone has specific fixes to my instructions, please leave them in the comments and I'll happily incorporate them.

Using electron-webpack without Node integration

Overview

The current version (as of 2019-02-02) of electron-webpack is set up with the assumption that your BrowserWindow instance has nodeIntegration: true. However, Electron is encouraging users to set nodeIntegration: false as a security precaution, and in the future BrowserWindows will have this setting set to false by default. Doing so now with electron-webpack throws an error because the index.html template has commonjs re

@sunvisor
sunvisor / jsdoc.vim
Created October 17, 2012 04:54
insert jsdoc style comment. (vim function)
" JSDoc形式のコメントを追加(functionの行で実行する)
" hogeFunc: function() の形式と function hogeFunc() に対応
" 関数定義でない場合は、コメントだけ出力する
function! AddJSDoc()
let l:jsDocregex = '\s*\([a-zA-Z]*\)\s*[:=]\s*function\s*(\s*\(.*\)\s*).*'
let l:jsDocregex2 = '\s*function \([a-zA-Z]*\)\s*(\s*\(.*\)\s*).*'
let l:line = getline('.')
let l:indent = indent('.')
let l:space = repeat(" ", l:indent)
@Raynos
Raynos / file.js
Created November 30, 2011 15:27
Recursive fs.watch
fs.readdir(srcPath, handleDirectoryRead.bind(null, srcPath));
function handleDirectoryRead(srcPath, err, files) {
files.forEach(handleFile.bind(null, srcPath));
}
function handleFile(srcPath, file) {
var uri = path.join(srcPath, file);
fs.stat(uri, handleStat.bind(null, uri));
}
@shuhei
shuhei / convert-textile.js
Created January 25, 2020 23:04
Convert textile files into markdown files
const { promises: fs } = require("fs");
const textile = require("textile-js");
const prettier = require("prettier");
const path = require("path");
async function main() {
const postsDir = path.resolve("source", "_posts");
const files = (await fs.readdir(postsDir)).filter(file =>
file.endsWith(".textile")
);
@necolas
necolas / _todo.md
Created June 30, 2012 18:07
Grunt tasks to process HTML files and produce a deploy directory of optimized files
  • Avoid reprocessing the same block in different HTML files.
  • Throw warning when processing a different block to an existing destination file. Hashing will avoid collisions, but introduce confusion.
  • Add file versioning for inline media and CSS images.
  • Avoid need for 'usemin' task - get the replacement element pattern from the first/last HTML element in actual block being replaced. Added benefit of preserving other attributes that may exist (e.g. title, media).

Acknowledgements: This is an adaption of some of Mickael Daniel's work on h5bp/node-build-script

@eikes
eikes / getElementsByClassName.polyfill.js
Created April 4, 2012 08:04
Polyfill for getElementsByClassName
// Add a getElementsByClassName function if the browser doesn't have one
// Limitation: only works with one class name
// Copyright: Eike Send http://eike.se/nd
// License: MIT License
if (!document.getElementsByClassName) {
document.getElementsByClassName = function(search) {
var d = document, elements, pattern, i, results = [];
if (d.querySelectorAll) { // IE8
return d.querySelectorAll("." + search);
@DTrejo
DTrejo / .gitignore
Created April 4, 2011 03:32
How to Readline - an example and the beginnings of the docs
node_modules/