Skip to content

Instantly share code, notes, and snippets.

View asyncanup's full-sized avatar

Anup Bishnoi asyncanup

View GitHub Profile
@asyncanup
asyncanup / react-in-a-tweet.js
Last active November 25, 2020 09:16
ReactJS in a tweet
React={Component:function(e){this.props=e},[C="createElement"]:(t,s,...a)=>t.bind?new t(s):(e=document[C](t),(()=>{for(n in s)e[n]=s[n]})(),g(a).map(t=>e[A](t.props?t.render():t.part?t:new Text(t))),e)},g=(e=>(e=e||[],e.map?e.flatMap(g):[e])),A="appendChild"
@asyncanup
asyncanup / another.lit
Created October 7, 2020 04:15
literate programming example. run.sh to see it in action
@s
--- dir/bla/yo.py
print("yo")
---
--- dir/blado.py
print("bla")
---
@asyncanup
asyncanup / tree.js
Last active October 21, 2020 23:40
Node.js list directory tree
const fs = require('fs');
function tree(dir, shortName = dir, prefix = '') {
const ls = fs.readdirSync(dir);
const isDir = ls.map(item => fs.statSync(`${dir}/${item}`).isDirectory());
const files = ls.filter((item, index) => !isDir[index]);
const dirs = ls.filter((item, index) => isDir[index]);
const filesPrefix = prefix + ' ';
console.log();
console.log(`${prefix}${shortName || '.'}/`);
if (files.length) {
<style id="jsbin-css">
body {
font: 14px "Century Gothic", Futura, sans-serif;
margin: 20px;
}
ol, ul {
padding-left: 30px;
}
var fs = require('fs'),
UglifyJS = require('uglify-js');
var express = require('express'),
app = express();
var repo = process.argv[2];
var html = fs.readFileSync(__dirname + '/' + repo + '/build/index.html').toString();
var js = UglifyJS.minify(__dirname + '/' + repo + '/build/' + repo + '.bundle.js').code;
//js = fs.readFileSync(__dirname + '/' + repo + '/build/' + repo + '.bundle.js').toString();
html = html.replace('<script src="' + repo + '.bundle.js"></script>', '<script>' + js + '</script>');
@asyncanup
asyncanup / simple-javascript-assert.md
Last active May 11, 2022 01:03
Simple JavaScript assert

Why you need assertions

It's better to fail with your own error than undefined is not a function.

A simple assertion solution would let your application fail early and fail at the right point in runtime execution. Allowing you to handle it better.

How you write assertions

#!/usr/bin/env coffee
fs = require 'fs'
sh = require 'execSync'
config = require './package.json'
name = config.name = "#{config.name}-semver"
version = config.version = config.version.replace(/\./g, '') + '.0.0'
@asyncanup
asyncanup / socket-io-namespace-bug.js
Last active August 29, 2015 14:05
Namespace bug in Socket.io 1.x
var assert = require('assert'),
http = require('http'),
sockets = require('socket.io'),
socketClient = require('socket.io-client');
describe('Socket.io', function () {
it('should take / as the default namespace', function (done) {
var port = 5001,
io = sockets.listen(port);