Skip to content

Instantly share code, notes, and snippets.

class SwitchSign(Exception):
pass
class BreakOut(Exception):
pass
def inner():
coef = 1
#!/bin/bash
function get_new_names() {
local input_names=$1
sed 's/[ \t]\+/:/g' $input_names
}
function gen_subst_func() {
local from=$1
local to=$2
@l04m33
l04m33 / async_file_wrapper.py
Last active April 10, 2017 14:45
Async file wrapper for asyncio
class AsyncFileWrapper(object):
DEFAULT_BLOCK_SIZE = 8192
def __init__(self, loop=None, filename=None,
fileobj=None, mode='rb'):
if (filename is None and fileobj is None) or \
(filename is not None and fileobj is not None):
raise RuntimeError('Confilicting arguments')
if filename is not None:
@l04m33
l04m33 / ssummary.py
Created October 27, 2014 02:27
Smarter summary plugin for Pelican
import logging
from pelican import signals
from pelican import contents
logger = logging.getLogger(__name__)
def initialized(pelican):
from pelican.settings import DEFAULT_CONFIG
import asyncdispatch, math
randomize()
proc r1() {.async.} =
echo("r1 going to sleep....")
await sleepAsync(random(1000) + 500)
if true:
raise newException(ValueError, "Oops!")
echo("r1 is awake.")
var dc = new DataCollection();
dc.add("ID", "45115");
Server.sendRequest("SupportOppose.voteOppose", dc, function(res) { console.log(res); });
@l04m33
l04m33 / clarifai.sh
Created May 16, 2016 02:45
Script to tag an image using Clarifai
#!/bin/sh
export CLIENT_ID="client-id" \
CLIENT_SECRET="client-secret" \
TOKEN_FILE="$HOME/.clarifai_token"
export TOKEN_API="https://api.clarifai.com/v1/token" \
TAG_API="https://api.clarifai.com/v1/tag"
local GPG_AGENT_BIN=/usr/bin/gpg-agent
local GPG_AGENT_ENV="$HOME/.gnupg/gpg-agent.env"
local GPG_CONNECT_AGENT_ERR_MSG="gpg-connect-agent: no gpg-agent running in this session"
function start_agent_withssh {
${GPG_AGENT_BIN} --quiet --enable-ssh-support --daemon 2> /dev/null > "${GPG_AGENT_ENV}"
chmod 600 "${GPG_AGENT_ENV}"
@l04m33
l04m33 / client.vim
Created February 6, 2017 10:39
Reproducing Vim channel_fill(...) issue
if exists('g:dummy_chan')
silent! call ch_close(g:dummy_chan)
endif
function! DummyCB(chan, msg)
echom '>>>> msg: ' . string(a:msg)
endfunction
let g:dummy_chan = ch_open('127.0.0.1:9999',
\ {'mode': 'json',
function! SpawnBufferWindow(name)
let dummy_buf = bufnr(a:name, v:true)
call setbufvar(dummy_buf, '&buftype', 'nofile')
call setbufvar(dummy_buf, '&bufhidden', 'hide')
call setbufvar(dummy_buf, '&swapfile', 0)
call setbufvar(dummy_buf, '&buflisted', 1)
execute 'belowright vertical split #' . dummy_buf
endfunction