Skip to content

Instantly share code, notes, and snippets.

$installLocation = "$env:LocalAppData\Programs\PowerToys"
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) (New-Guid)
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
Push-Location $tempDir
$latestPowerToys = Invoke-WebRequest "https://api.github.com/repos/microsoft/PowerToys/releases/latest" | ConvertFrom-Json
$latestVersion = $latestPowerToys.tag_name.Substring(1)
$isInstalled = Test-Path "$installLocation\PowerToys.exe"
if ($isInstalled) {
#!/usr/bin/env python3
import sys
import subprocess
import re
SSH_COMMAND_PATTERN = r'ssh -t -i (?P<IdentityFile>.+?)(?P<options> -o .+) (?P<User>\w+)@(?P<HostName>\w+\.\d+)'
def main():
instance_name = sys.argv[1]
command = ['gcloud', 'compute', 'ssh', '--tunnel-through-iap', '--dry-run']
@cedar101
cedar101 / gcp_ssh_config.py
Last active September 24, 2020 06:02
Generate Host info in ~/.ssh/config from 'gcloud compute ssh' using IAP
#!/usr/bin/env python3
import sys
import subprocess
import re
SSH_COMMAND_PATTERN = r'ssh -t -i (?P<IdentityFile>.+?)(?P<options> -o .+) (?P<User>\w+)@(?P<HostName>\w+\.\d+)'
def main():
instance_name = sys.argv[1]
command = ['gcloud', 'compute', 'ssh', '--tunnel-through-iap', '--dry-run']
#!/usr/bin/env python
import sys
from pathlib import Path
from pprint import pprint
from typing import NamedTuple
import functools
import contextlib
import sqlparse
import fire
@cedar101
cedar101 / gcloud_loguru.py
Last active June 25, 2020 03:14
Stackdriver logging using loguru
#!/usr/bin/env python
import sys
import traceback
import functools
import google.cloud.logging
from loguru import logger
def without_keys(d, keys):
return {x: d[x] for x in d if x not in keys}
@cedar101
cedar101 / app.py
Last active April 24, 2017 10:24
Python mixin classes for dependency injection
import os
from resources import AbstractDatabaseConnector, EnvInterface
class EnvVarGetter(EnvInterface):
@property
def env(self):
'''Get env from envvar'''
return os.environ['APP_ENV']
@cedar101
cedar101 / compose.py
Created March 23, 2017 06:29
function composition of python
>>> import re
>>> from functools import reduce, partial
>>> from operator import add, itemgetter
>>> def compose2(f, g):
... return lambda *args, **kwargs: f(g(*args, **kwargs))
>>> def compose(*functions):
... return reduce(compose2, functions)
@cedar101
cedar101 / get_intervals.py
Last active March 22, 2017 08:51
Get intervals from iterator
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from itertools import accumulate, groupby, islice, tee
from operator import itemgetter
from collections import deque
from functools import partial, wraps
def trace_iter(source):
2015-11-18 16:40:02 +0900
./configure
--prefix=/usr/local/Cellar/python/2.7.10_2
--enable-ipv6
--datarootdir=/usr/local/Cellar/python/2.7.10_2/share
--datadir=/usr/local/Cellar/python/2.7.10_2/share
--enable-framework=/usr/local/Cellar/python/2.7.10_2/Frameworks
--without-ensurepip
--without-gcc
@cedar101
cedar101 / transcribe.py
Created August 29, 2012 07:57 — forked from ehazlett/transcribe.py
Logs Redis Pub/Sub messages to MongoDB
#!/usr/bin/env
#
# Requirements:
# argparse==1.2.1
# pymongo==2.1
# redis==2.4.10
import redis
import pymongo
import argparse