Skip to content

Instantly share code, notes, and snippets.

const std = @import("std");
const net = std.net;
const fs = std.fs;
const os = std.os;
pub const io_mode = .evented;
pub fn main() anyerror!void {
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = &general_purpose_allocator.allocator;
@r2dev
r2dev / build.bat
Created April 18, 2021 20:23
httpd in c
@echo off
IF NOT EXIST .\build mkdir .\build
pushd .\build
cl -nologo -Zi -FC ..\main.cpp Ws2_32.lib
popd
@r2dev
r2dev / leetcode.md
Last active September 2, 2020 16:31
leetcode

Majority Element - 169

solution 1: sort and choose the middle one

solution 2: hash map

solution 3: voting, lets assume the first is the right candidate, if we see zero count, we assign the candidate, if we see the vote is toward the current canadidate, we add vote count by one, if we see different canadidates, we deduct the value by one. The right answer is the remaining canadidate

@r2dev
r2dev / phone-input.directive.ts
Last active March 1, 2019 20:07
Angular 2 cleave.js phone component
import { Directive, Input, forwardRef, ElementRef, AfterViewInit, OnDestroy } from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'
import Cleave from 'cleave.js'
@Directive({
selector: '[phone-input]',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => PhoneNumberInputDirective),
multi: true
import React, { Component } from "react";
let keys = {
end: 35,
home: 36,
left: 37,
up: 38,
right: 39,
down: 40,
delete: 46,
enter: 13,
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta content="width=device-width,minimum-scale=1.0" name="viewport">
<title>Hello World</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
class I18n {
constructor(locale) {
this.locale = locale;
this.subscriptions = [];
this.text = window[locale]
}
setLocale(locale) {
if (this.locale !== locale) {
@r2dev
r2dev / index.html
Created December 14, 2017 22:58
vuex
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb"
crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ"
@r2dev
r2dev / test.jsx
Created March 17, 2017 16:25
test.js
const SelectProvince = ({ provinces, value, onChange }) => (
<select value={value} onChange={onChange}>
{provinces.map((pro, index) => {
return (
<option value={pro} key={index}>
{pro}
</option>
);
})}
</select>
const SelectProvince = ({ provinces, value, onChange }) => (
<select value={value} onChange={onChange}>
{provinces.map((pro, index) => {
return (
<option value={pro} key={index}>
{pro}
</option>
);
})}
</select>