Skip to content

Instantly share code, notes, and snippets.

@naholyr
naholyr / test.jsx
Last active October 16, 2021 11:08
import React, { Fragment, Component } from 'react';
import ReactDOM from 'react-dom';
class ContextData {
watchers = []
constructor(initialState = {}) {
this.state = initialState
@naholyr
naholyr / compare.php
Created February 22, 2012 16:27
Extract namespace from a PHP file
<?php
// Works in every situations
function by_token ($src) {
$tokens = token_get_all($src);
$count = count($tokens);
$i = 0;
$namespace = '';
$namespace_ok = false;
while ($i < $count) {
@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 / prerequisites-react.md
Created February 28, 2020 21:40
Prerequisites for React.js express training

React.js training prerequisites