Skip to content

Instantly share code, notes, and snippets.

import React, { Component } from "react";
let keys = {
end: 35,
home: 36,
left: 37,
up: 38,
right: 39,
down: 40,
delete: 46,
enter: 13,
@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
@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 / 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
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;