Skip to content

Instantly share code, notes, and snippets.

View brain-zhang's full-sized avatar

brainzhang brain-zhang

View GitHub Profile
@brain-zhang
brain-zhang / ballot.sol
Created September 16, 2018 02:32
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=false&gist=
pragma solidity ^0.4.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
@brain-zhang
brain-zhang / ballot.sol
Created September 15, 2018 09:42
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=false&gist=
pragma solidity ^0.4.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
https://press.one/p/address/v?s=a5f02c2979981c7c560c758f631234a9f35121e9e79149a2071d0700e0c360ba4483851872375873a9b5f9138b5973066c641bd8c58a72c38b46f60a770c0d3a0&h=436a3ddf95ac02c52932c1233118c55971dc134bd2ca422dcf241670419ff40f&a=7e32e3deba87efcd35bc6d1ab355d85c50aa60bd&f=P1&v=2
We couldn’t find that file to show.
#!/bin/bash
# References
# http://www.computerhope.com/unix/nc.htm#03
# https://github.com/daniloegea/netcat
# http://unix.stackexchange.com/questions/26715/how-can-i-communicate-with-a-unix-domain-socket-via-the-shell-on-debian-squeeze
# http://unix.stackexchange.com/questions/33924/write-inside-a-socket-open-by-another-process-in-linux/33982#33982
# http://www.linuxjournal.com/content/more-using-bashs-built-devtcp-file-tcpip
# http://www.dest-unreach.org/socat/
# http://stuff.mit.edu/afs/sipb/machine/penguin-lust/src/socat-1.7.1.2/EXAMPLES
import subprocess
def check_output(args, stderr=None):
'''Run a command and capture its output'''
return subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=stderr).communicate()[0]
if __name__ == '__main__':
check_output(['df', '-h'])
check_output(['df', '-h'], stderr=subprocess.STDOUT)
@brain-zhang
brain-zhang / simple_xml_parse.py
Last active August 29, 2015 14:09
simple parse xml file(utf-8) with comment
#!/bin/env python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
class CommentedTreeBuilder(ET.XMLTreeBuilder):
def __init__(self, html = 0, target = None):
ET.XMLTreeBuilder.__init__(self, html, target)
self._parser.CommentHandler = self.handle_comment
@brain-zhang
brain-zhang / compress.py
Created August 18, 2014 06:47
compress each file in a folder to zip
#!/bin/env python
# -*- coding: utf-8 -*-
"""
--A|
|-a.pack
|-aa.pack
|-B|
|-b.pack
|-b.pack
import npyscreen, curses
class StatusWidget(npyscreen.wgwidget.Widget):
def update(self, clear=True):
if clear == True:
self.clear()
self.status = npyscreen.Textfield(self.parent, rely=self.rely, relx=0, editable=1)
import npyscreen
from datetime import datetime
class DateForm(npyscreen.Form):
def while_waiting(self):
npyscreen.notify_wait("Update")
self.display()
def create(self):
self.add(npyscreen.FixedText, value=datetime.now(), editable=False)