Skip to content

Instantly share code, notes, and snippets.

@prashnts
prashnts / asyncdownload.py
Created February 15, 2017 08:00
Asyncio Python -- Download in parallel
import aiohttp
import asyncio
BATCH_SIZE = 20
POOL_SIZE = 5
async def get_content(client, url):
async with client.get(url) as response:
return await response.text()
def take(iterable, num):
for i, elem in enumerate(iterable):
yield elem
if i + 1 == num:
break
def chain_pop(*iterable):
for elem in iterable:
while True:
try:
@foaly-nr1
foaly-nr1 / Event.php
Last active August 19, 2020 12:44
NotOverlapping Symfony date period validator
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Validator\Constraints\NotOverlapping;
/**
* @NotOverlapping("period")
*/
@Wizmann
Wizmann / workflowy-with-image.js
Last active June 14, 2023 13:29
workflowy-with-image.js
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://workflowy.com/*
// @grant none
// ==/UserScript==
/* jshint -W097 */
@yuya-takeyama
yuya-takeyama / peco_phprf
Last active August 20, 2021 19:34
peco で PHP のビルトイン関数の引数定義見るヤツ
#!/bin/sh
selected_function=$(php -r '$fs=get_defined_functions();echo join(PHP_EOL, $fs["internal"]), PHP_EOL;' | sort | peco)
if [ -n "$selected_function" ]; then
php --rf "$selected_function"
exit 0
else
echo "No function is selected"
exit 1
fi
@liunian
liunian / gist:9338301
Last active October 6, 2023 20:48
Human Readable File Size with PHP
<?php
# http://jeffreysambells.com/2012/10/25/human-readable-filesize-php
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
echo human_filesize(filesize('example.zip'));
@iambibhas
iambibhas / scopes.txt
Last active April 8, 2024 20:37
Sublime Text 2: Snippet scopes
Here is a list of scopes to use in Sublime Text 2 snippets -
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
CoffeeScript: source.coffee