Skip to content

Instantly share code, notes, and snippets.

@naholyr
naholyr / 1-useless-stack.js
Last active June 8, 2021 08:29
Make stack traces useful again
var fs = require('fs');
// Here is a simple function that reads a file and makes something with its content
function readLog1 (cb) {
// Notice how I even gave a name to my callback, this is useful for stack traces, everyone says…
fs.readFile('file-not-found.log', function onRead1 (err, content) {
// Usual error handling
if (err) return cb(err);
@naholyr
naholyr / function-argnames.js
Created February 19, 2012 18:30
JS Introspection: extract function parameter names
Function.prototype.argNames = function () {
// Extract function string representation: hopefully we can count on it ?
var s = this.toString();
// The cool thing is: this can only be a syntactically valid function declaration
s = s // "function name (a, b, c) { body }"
.substring( // "a, b, c"
s.indexOf('(')+1, // ----------------^
s.indexOf(')') // ------^
);
@naholyr
naholyr / run-casper.sh
Created July 12, 2012 16:01
Click on checkbox with CasperJS
casperjs test test-checkbox.js
@naholyr
naholyr / .gitignore
Last active October 29, 2020 21:46
res.redirect not working as expected
node_modules
@naholyr
naholyr / monkey-patch.js
Created December 21, 2012 11:52
JS monkey patching
// Original method
var object = {
method: function (x, y) {
return x+y;
}
}
// Add operations before or after!
object.method = (function (original) {
return function (x, y) {
UNIT=MM
BORDER=NONE,#000000,0,MARKDOT,#000000
GAP=5,5,ON
PAGE=210,297,PORTRAIT,HV
DPI=300
CARDSIZE=63,88
LINK=cards.xls,image
IMAGE=,[IMAGE],0,0,100%,100%,0,PTA
UNIT=MM
BORDER=NONE,#000000,0,MARKDOT,#000000
GAP=10,10,ON
PAGE=210,297,PORTRAIT,HV
DPI=300
CARDSIZE=40,55
LINK=cards.xls,image
IMAGE=,[IMAGE],0,0,100%,100%,0,PTA
@naholyr
naholyr / block-social-networks.sh
Created December 21, 2011 15:09
Bash Pomodoro using libnotify
#!/bin/bash
# Destination: ~/.pomodoro/hooks/work.d/
# Goal: block access to Twitter and Facebook while in a Pomodoro
# Note: won't work if you use Chrome, as it maintains an internal (not flushable from CLI) DNS cache. Fuck it.
# This file must be able to touch "/etc/hosts":
# The best way would be to create a group able to modify the "/etc/hosts" file:
# $ sudo addgroup host-manager
# $ sudo chgrp host-manager /etc/hosts
@naholyr
naholyr / prerequisites-react.md
Created February 28, 2020 21:40
Prerequisites for React.js express training

React.js training prerequisites

import * as React from 'react';
// TODO inject counters
const Counter = () => {
const [value, setValue] = React.useState(1);
const incr = React.useCallback(() => setValue(value + 1), [value]);
return (
<button type="button" onClick={incr}>
Click to incr. ({value})