Skip to content

Instantly share code, notes, and snippets.

View siburu's full-sized avatar

YOSHIDA Masanori siburu

View GitHub Profile
def prob(a, n, t):
rest = t - a
if rest < 2:
return 0
if rest == 2:
return 4
if rest <= n + 1:
return rest + 1
if rest <= 2 * n:
return 2 * n - rest + 1
def calc_import_path(target: str, start: str) -> str:
import os
target = os.path.join('root', target)
start = os.path.join('root', start)
d = os.path.relpath(os.path.dirname(target), os.path.dirname(start))
if not d.startswith('.'):
d = os.path.join('.', d)
return os.path.join(d, os.path.basename(target))
#define _GNU_SOURCE
#include <stdio.h>
#include <ftw.h>
int walk(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
static const char *flag2msg[] = {
[FTW_F] = "Regular file.",
[FTW_D] = "Directory.",
[FTW_DNR] = "Unreadable directory.",
@siburu
siburu / rust-libc-tcpudp.rs
Last active July 21, 2020 17:51
TCP/UDP open/setsockopt/bind/listen/connect/accept/send/recv/shutdown/close by libc crate
use libc::*;
use std::convert::TryInto;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
struct Cli {
#[structopt(subcommand)]
cmd: Command,
}
package main
type S struct {
i int
}
func main() {
var a []*int
for _, s := range []S{{1},{2},{3}} {
a = append(a, &s.i)
package main
import "github.com/ethereum/go-ethereum/common"
func main() {
hashes := []common.Hash{{1}, {2}, {3}}
ss := convertDirectly(hashes)
checkResult("direct", ss)
@siburu
siburu / main.rs
Last active March 28, 2019 05:12
struct Hoge {
agony: String
}
impl Drop for Hoge {
fn drop(&mut self) {
println!("drop: {}", self.agony);
}
}
@siburu
siburu / Refunder.sol
Created March 6, 2019 06:36
How to implement gas-free tx
pragma solidity >=0.5.0;
contract Refunder {
modifier fullyRefund() {
uint256 gas = gasleft();
_;
gas = gas - gasleft() + 21000;
msg.sender.transfer(gas * tx.gasprice);
}
@siburu
siburu / fork-wait.go
Created April 28, 2016 09:33
Fork and wait for a child in Golang
package main
import (
"os"
"syscall"
"time"
)
const (
CHILD_ARG = "child"
package main
import "math/rand"
func main() {
n := 0
for n < 4 {
for n = 0; rand.Int()%2 == 0; n++ {
println("ズン")
}