Skip to content

Instantly share code, notes, and snippets.

@yutopio
yutopio / ip.vbs
Created December 7, 2020 11:39
Get IP for the machine.
Option Explicit
Dim oReq
Set oReq = CreateObject("MSXML2.XMLHTTP.3.0")
oReq.Open "GET", "http://checkip.dyn.com/", False
oReq.Send
Dim oDom
Set oDom = CreateObject("MSXML2.DOMDocument")
oDom.LoadXML(oReq.ResponseText)
@yutopio
yutopio / monitor.yaml
Created November 23, 2019 07:01
Swarm visualizer + cAdvisor + InfluxDB + Grafana stack
# docker stack deploy -c monitor.yaml monitor
# docker exec `docker ps | grep -i influx | awk '{print $1}'` influx -execute 'CREATE DATABASE cadvisor'
version: '3.7'
services:
swarm-visualizer:
image: dockersamples/visualizer
ports:
- "9000:8080"
volumes:
@yutopio
yutopio / Calc.csproj
Created March 6, 2018 13:40
Simple math calculator
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\Antlr4.CodeGenerator.4.6.4\build\Antlr4.CodeGenerator.props" Condition="Exists('packages\Antlr4.CodeGenerator.4.6.4\build\Antlr4.CodeGenerator.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EE3E54A6-D9F2-47D9-A017-0E3FCCB12700}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Calc</RootNamespace>
@yutopio
yutopio / http.cs
Created March 3, 2018 01:10
Example of simple HTTP client / server by using Socket
using System;
using System.Net;
using System.Net.Sockets;
class Program
{
static void Main(string[] args)
{
var s = new Socket(
AddressFamily.InterNetwork,
@yutopio
yutopio / ProducerConsumer.cs
Created March 1, 2018 09:24
Producer-Consumer problem implementation
using System;
using System.Threading;
class Program
{
static int prodIndex = 0;
static int consIndex = 0;
static Semaphore empty, filled;
static string[] buffer;
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static readonly Random rnd = new Random();
static void Main(string[] args)
{
@yutopio
yutopio / cert.cs
Created February 20, 2017 12:14
Certificate generation with BouncyCastle C#
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.Sec;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Operators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Security;
using System;
using System.Runtime.CompilerServices;
using static System.Console;
// No effect...
//[CompilationRelaxations(CompilationRelaxations.NoStringInterning)]
class Program
{
const string kHello = "HelloWorld";
using System;
using System.Runtime.CompilerServices;
using System.Threading;
class Program
{
static readonly EventWaitHandle wh = new ManualResetEvent(false);
static volatile bool beforeSet = false;
static volatile bool afterSleep = false;
@yutopio
yutopio / Volatile.cs
Last active September 23, 2016 06:28
using System;
using System.Threading;
class Program
{
class Flag
{
public bool done;
}