Skip to content

Instantly share code, notes, and snippets.

View Cyber-Neuron's full-sized avatar
💭
unset PYTHONPATH

Cyber-Neuron

💭
unset PYTHONPATH
View GitHub Profile
@Cyber-Neuron
Cyber-Neuron / Git commands
Created March 16, 2017 10:22
Git commands
set to bare: git config --bool core.bare true
switch branch in bare: git symbolic-ref HEAD refs/heads/XXXXX
push to remote: git push REMOTE_NAME BRANCH_NAME
add a remote working copy: git remote add pb https://github.com/paulboone/ticgit
@Cyber-Neuron
Cyber-Neuron / generators.txt
Created March 19, 2017 16:37
Using iterators and generators in multi-threaded applications
Using iterators and generators in multi-threaded applications
24 May 2012 – Bangalore
Python iterators and generators have almost the same behavior, but there are subtle differences, especially when the iterator/generator is used in a multi-threaded application.
Here is an example to demonstrate that behavior.
import threading
def count():
#From https://github.com/tensorflow/tensorflow/issues/6322
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@Cyber-Neuron
Cyber-Neuron / http_stream.py
Created October 1, 2018 20:34
restore http stream from pcap via dpkt
# encoding=utf8
import dpkt
from collections import OrderedDict
import json
import string
import fire
import gzip
_printable = string.ascii_letters + string.digits + string.punctuation + ' '
@Cyber-Neuron
Cyber-Neuron / gpu_run.sh
Created November 29, 2018 19:04
gpu_run.sh 2 python cnn.py
#!/bin/bash
used=`nvidia-smi | sed 's/\s\s*/ /g' |cut -d " " -f1,2,3|grep "| [0-9]"|grep Tesla -v|cut -d" " -f2`
allgpus=`nvidia-smi | sed 's/\s\s*/ /g' |cut -d " " -f1,2,3|grep "| [0-9]"|grep Tesla|cut -d" " -f2`
#comm -12 <(echo -e $used| sort -u) <(echo -e $allgpus | sort -u)
ava=`bash -c "comm -3 <(grep -oP '\d+' <<<\"$allgpus\" | sort) <(grep -oP '\d+' <<<\"$used\" | sort) | tr -d '\t' | paste -sd','"`
reqed=`echo $ava|cut -d"," -f1-$1`
#echo $reqed,
cmds=`echo $@|cut -d" " -f2-`
#echo $cmds
CUDA_VISIBLE_DEVICES=$reqed $cmds
@Cyber-Neuron
Cyber-Neuron / subsettree.py
Created February 13, 2019 09:48
输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)
# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def HasSubtree(self, pRoot1, pRoot2):
if pRoot2 is None:
return False
@Cyber-Neuron
Cyber-Neuron / balancebintree.py
Created February 13, 2019 23:25
输入一棵二叉树,判断该二叉树是否是平衡二叉树。
# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def IsBalanced_Solution(self, pRoot):
# write code here
self.b=True
#! /usr/bin/env python3
# https://raw.githubusercontent.com/python/cpython/main/Tools/scripts/reindent.py
# Released to the public domain, by Tim Peters, 03 October 2000.
"""reindent [-d][-r][-v] [ path ... ]
-d (--dryrun) Dry run. Analyze, but don't make any changes to, files.
-r (--recurse) Recurse. Search for all .py files in subdirectories too.
-n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
-v (--verbose) Verbose. Print informative msgs; else no output.
@Cyber-Neuron
Cyber-Neuron / autofs.md
Created March 29, 2022 02:34 — forked from rudelm/autofs.md
Use autofs on Mac OS X to mount network shares automatically during access

Autofs on Mac OS X

With autofs you can easily mount network volumes upon first access to the folder where you want to mount the volume. Autofs is available for many OS and is preinstalled on Mac OS X so I show you how I mounted my iTunes library folder using this method.

Prepare autofs to use a separate configuration file

autofs needs to be configured so that it knows where to gets its configuration. Edit the file /etc/auto_master and add the last line:

#
# Automounter master map
#

+auto_master # Use directory service