Skip to content

Instantly share code, notes, and snippets.

/* So how does this work?
I'm using ANSI escape sequences to control the behavior of the terminal while
cat is outputting the text. I deliberately place these control sequences inside
comments so the C++ compiler doesn't try to treat them as code.*/
//
/*The commands in the fake code comment move the cursor to the left edge and
clear out the line, allowing the fake code to take the place of the real code.
And this explanation uses similar commands to wipe itself out too. */
//
#include <cstdio>
@DIYer22
DIYer22 / Detection Python Environment, Especially distinguish Spyder, Jupyter notebook, Qtconsole.py
Created May 8, 2018 12:46
Detection Python Environment, Especially distinguish Spyder, Jupyter notebook, Qtconsole
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue May 8 20:40:30 2018
@author: yanglei
"""
'''
# Detection Python Environment, Especially distinguish Spyder, Jupyter notebook, Qtconsole
@jmbjorndalen
jmbjorndalen / asyncio_executors_threads_procs.py
Created April 26, 2018 08:10
Combining Python 3 asyncio coroutines with thread pool and process pool executors
#!/usr/bin/env python3
# Combining coroutines running in an asyncio event loop with
# blocking tasks in thread pool and process pool executors.
#
# Based on https://pymotw.com/3/asyncio/executors.html, but this version runs both
# threads and processes at the same time and interleaves them with asyncio coroutines.
#
# All appears to be working.
#
@garfieldnate
garfieldnate / imgcat.py
Last active October 9, 2020 09:16
Python 2/3 version of imgcat tool, which displays images inline in iTerm2
from __future__ import print_function
import base64
import os
import select
import sys
# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
@f0k
f0k / nvidia_boost.sh
Created December 6, 2017 17:45
Set Nvidia GPU application clocks and power limits to maximum supported values
#!/bin/bash
# Sets each CUDA device to persistence mode and sets the application clock
# and power limit to the device's maximum supported values.
# When run with "--dry-run" as first command line argument or not as superuser,
# will display the commands, otherwise it will execute them.
#
# Hint: To run this at boot time, place this script in /root and create a file
# /etc/cron.d/nvidia_boost with the following single line:
# @reboot root /root/nvidia_boost.sh >/dev/null
#
@simoncos
simoncos / miniconda_on_rpi.md
Last active October 7, 2024 11:50
Install Miniconda 3 on Raspberry Pi
@brianbruggeman
brianbruggeman / LICENSE
Last active May 31, 2024 09:02
Convert Viscosity to Open VPN
Public Domain
@Tushar-N
Tushar-N / pad_packed_demo.py
Last active October 27, 2024 15:17
How to use pad_packed_sequence in pytorch<1.1.0
import torch
import torch.nn as nn
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
seqs = ['gigantic_string','tiny_str','medium_str']
# make <pad> idx 0
vocab = ['<pad>'] + sorted(set(''.join(seqs)))
# make model
@dolaameng
dolaameng / variable_rnn_torch.py
Last active December 31, 2021 05:19
Variable Length Sequence for RNN in pytorch Example
import torch
import torch.nn as nn
from torch.autograd import Variable
batch_size = 3
max_length = 3
hidden_size = 2
n_layers =1
# container
from graphviz import Digraph
import torch
from torch.autograd import Variable, Function
def iter_graph(root, callback):
queue = [root]
seen = set()
while queue:
fn = queue.pop()
if fn in seen: