Skip to content

Instantly share code, notes, and snippets.

@appkr
appkr / result.md
Last active April 16, 2022 06:01
Performance Comparison for Dynamically-typed Non-compile Languages

Test Result

Language Execution time(sec)
JS with V8 (Node 8.11) 3.18
PHP 7.2 28.026075124741
PHP 7.0 28.537676095963
Ruby 2.5 37.355172
Python 2.7 70.2023770809
Python 3.6 99.59470009803772
@johnssuh
johnssuh / What does asyncio.sleep(0) Do?
Created July 4, 2018 09:24
Some cool stuff with asyncio
import asyncio
class DummyAPI:
async def get(self, number):
print(f"GET {number} executed")
await asyncio.sleep(number)
return number, "a"
async def context_switched_get(self):
dispatch_list = []
@kokospapa8
kokospapa8 / time measuring decorator
Created June 27, 2018 11:41
Time measure decorator for coroutine
```
from sanic.log import logger
from insanic.conf import settings
from functools import wraps
from time import time
def measure_time(f):
@wraps(f)
@radekk
radekk / detect.malicious.npm.sh
Last active April 27, 2020 04:43
Detect malicious npm packages published by ~hacktask account
#!/bin/bash
# Author: @radekk
# List of vulnerable packages is from https://twitter.com/iamakulov/status/892485192883073024
# ----------------------
_IFS=$IFS
_COUNTER=0
_COUNTER_ALL=0
_SCAN_PATH=${1:-~/}
_VULN_PACKAGES="babelcli crossenv cross-env.js d3.js fabric-js ffmepg gruntcli http-proxy.js jquery.js mariadb mongose mssql.js mssql-node mysqljs nodecaffe nodefabric node-fabric nodeffmpeg nodemailer-js nodemailer.js nodemssql node-opencv node-opensl node-openssl noderequest nodesass nodesqlite node-sqlite node-tkinter opencv.js openssl.js proxy.js shadowsock smb sqlite.js sqliter sqlserver tkinter"
_REGEXP="(babelcli|crossenv|cross-env\.js|d3\.js|fabric-js|ffmepg|gruntcli|http-proxy\.js|jquery\.js|mariadb|mongose|mssql\.js|nodecaffe|nodefabric|node-fabric|nodeffmpeg|nodemailer-js|nodemailer\.js|nodemssql|node-opencv|node-opensl|node-openssl|noderequest|nodesass|nodesqlite|node-sqlite|node-tkinter|opencv\.js|openssl\.js|proxy\.js|shadowsock|smb|sqlite\.js|sqliter|sqlserver|tkinter)"
@Bradshaw
Bradshaw / better_sin.js
Created June 28, 2017 08:47
Better version of Math.sin for javascript
var old_sin = Math.sin;
Math.sin = function(x) {
if (typeof x == "number" && isFinite(x)){
return old_sin(x);
}
var str = "" + x;
if (str.length>0){
str = str.repeat(Math.ceil(Math.max(1,18/str.length)));
}
var sinstr = "|\n";
@VictorTaelin
VictorTaelin / promise_monad.md
Last active May 10, 2024 04:22
async/await is just the do-notation of the Promise monad

async/await is just the do-notation of the Promise monad

CertSimple just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I wholeheartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but failed too. Finally, async/await is here and, combined with Promises, it solves the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing

@rockwood
rockwood / Readme.md
Last active May 4, 2018 15:55
Seoul Elixir Meetup

1. Install Phoenix 1.3

mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez

2. Create a new Phoenix project

mix phx.new demo

3. Create the database

@BaseCase
BaseCase / dc_2017_biblio.md
Last active January 23, 2020 05:13
List of resources recommended or mentioned by the speakers at Deconstruct 2017

Deconstruct 2017 Bibliography

Here are all of the resources mentioned by Deconstruct 2017 speakers, along with who recommended what. Please post a comment if I missed something or have an error!

DC 2017 Speakers' Choice Gold Medalist

  • Seeing Like a State by James Scott

Books

  • Public Opinion by Walter Lippmann (Evan Czaplicki)
  • A Pattern Language by Christopher Alexander (Brian Marick)
  • Domain Driven Design by Eric Evans (Brian Marick)
@iain
iain / README.md
Last active December 12, 2022 00:56
Minimaliain ZSH theme

Minimaliain

This is my ZSH theme. I've had it for years, this adoption is for use as an antigen theme.

The git prompt looks like this:

  • Current git project name (blue: last exit status was ok, red: last exit status failed)
  • Time since last commit
  • Branch name or commit ref (green: working tree is clean, red: dirty working tree)
  • Merge status (↑ is you can push, ↓ is you can pull, ↕ means you have diverged)
@Rich-Harris
Rich-Harris / footgun.md
Last active June 1, 2024 17:52
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological