Skip to content

Instantly share code, notes, and snippets.

View vamdt's full-sized avatar

vamdt vamdt

  • Foggy Beijing
View GitHub Profile
import subprocess
import re
# https://github.com/microsoft/WSL/issues/4210
def get_address_info():
s1 = subprocess.Popen(["ifconfig"], stdout=subprocess.PIPE)
out_string = s1.stdout.read().decode("utf-8")
@Konfekt
Konfekt / okular-markdown-preview-vim.md
Last active March 20, 2024 16:10
A dead-simple markdown previewer in Vim thanks to KDE's document viewer Okular

KDE's document viewer Okular renders markdown as HTML (and reloads it automatically on changes.) Thus, simply open the markdown file currently edited in Vim in Okular to be all set!

To start an GUI application from Vim, without freezing, hit-<enter> prompts or scrambling screen lines, one can add a command such as

if has('unix')
 command! -complete=shellcmd -nargs=1 -bang Silent execute ':silent !' . (0 ? 'nohup ' .  . '/dev/null 2&gt;&amp;1 &amp;' : ) | execute ':redraw!'
@charithe
charithe / client.go
Created March 26, 2017 16:28
GRPC Opentracing Interceptors
package otgrpc
import (
context "golang.org/x/net/context"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
"github.com/opentracing/opentracing-go/log"
"google.golang.org/grpc"
)
@weidagang
weidagang / distributed_mvcc_cross_row_transaction.py
Last active December 29, 2020 11:44
Distributed MVCC based cross-row transaction
#!/usr/bin/python3.5
# Author: Dagang Wei (github.com/weidagang)
# Created: 2016-11-19
# Last modified: 2016-11-27
# License: MIT
# Self link: https://gist.github.com/weidagang/1b001d0e55c4eff15ad34cc469fafb84
#
# This code demonstrates the core algorithm for distributed MVCC based cross-row
# transactions. The algorithm is built on top of a distributed key-value database

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.

@raphw
raphw / BootstrapAgent.java
Last active March 26, 2024 06:56
An example agent that intercepts a method of the bootstrap class loader.
package net.bytebuddy;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassInjector;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
template <typename Left, typename Right>
struct ConcatExpr;
template <typename Left, typename Right>
struct AltExpr;
template <typename SubExpr>
struct RepeatExpr;
template <char ch>
@oledid
oledid / turn-off-screen.ps1
Created September 24, 2015 07:15
PowerShell: Turn off computer screen
# Source: http://www.powershellmagazine.com/2013/07/18/pstip-how-to-switch-off-display-with-powershell/
# Turn display off by calling WindowsAPI.
# SendMessage(HWND_BROADCAST,WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF)
# HWND_BROADCAST 0xffff
# WM_SYSCOMMAND 0x0112
# SC_MONITORPOWER 0xf170
# POWER_OFF 0x0002

Let's solve the following physics problem using Symbolism, a computer algebra library for C#.

One strategy in a snowball fight is to throw a first snowball at a high angle over level ground. While your opponent is watching the first one, you throw a second one at a low angle and timed to arrive at your opponent before or at the same time as the first one.

Assume both snowballs are thrown with a speed of 25.0 m/s.

The first one is thrown at an angle of 70.0° with respect to the horizontal.