Skip to content

Instantly share code, notes, and snippets.

View hpcx82's full-sized avatar

hpcx hpcx82

  • Shanghai
View GitHub Profile
@hpcx82
hpcx82 / test3_dp.cpp
Last active June 26, 2024 23:14
test3_dp.cpp
#include <bits/stdc++.h>
#include <lab.H>
using namespace std;
float calculateDistance(int x, int y)
{
return sqrt(x*x + y*y);
}
#pragma once
#include <atomic>
#include <algorithm>
#include "AlignAs.H"
/*
* 1. release-acquire memory order
* 2. false sharing and cache line
* 3. alignas
*
def look_and_say(member):
while True:
num = []
count = []
pre = None
for ele in member:
if len(num) > 0 and pre == ele:
count[len(count)-1] += 1
else:
num += [ele]
// StlAlgo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <array>
#include <algorithm>
#include <iterator> // ostream_iterator
#include <iostream>
@hpcx82
hpcx82 / programsegment.cpp
Created December 8, 2012 12:40
Display address of program segments
#include <iostream>
using namespace std;
// .data - read-write data
int rwdata = 100;
// .rodata - read-only data
const char* rodata = "hello, world";
@hpcx82
hpcx82 / monitorweb.pl
Created December 2, 2012 01:15
monitor a domain, send a mail if it is no longer "pendingDelete"
use strict;
my $targetPage = $ARGV[0]; #http://www.kingtoo.com/reg/whois.asp?domain=douban.com
print $targetPage . "\n";
my @page = `curl $targetPage | iconv -f gb2312 -t utf8`;
chomp @page;
my $domainStatus;
for my $line (@page)
{
@hpcx82
hpcx82 / sort-by-color.lua
Created November 28, 2012 13:27
数组有N个元素,每个元素可能是红色、白色或蓝色。现在要把它们按照颜色排序(左红中白右蓝)。写出代码。
function printa(arr)
for _, v in ipairs(arr) do
io.write(v .. " ")
end
io.write("\n")
end
-- use consecutive number to represent the colors, like:
-- red: 1
@hpcx82
hpcx82 / bar-premake-use.lua
Created November 23, 2012 01:48
Use lua to manipulate functions
LIBS = {}
DEPS = {}
EXPORTS = {'bar'}
bar = {}
function bar.use_nonpopular_bar()
print 'bar.use_nonpopular_bar'
end
@hpcx82
hpcx82 / subgraph.dot
Created November 22, 2012 06:37
graphviz dot subgraph example
digraph
{
subgraph cluster_solution
{
label="solution"
App;
foo;
baz;
}
App -> foo;
@hpcx82
hpcx82 / producer-consumer-coroutine.lua
Created November 17, 2012 13:25
use coroutine to implement producer-consumer
function consumer(prod)
while true do
local x = receive(prod)
print(x)
end
end
function receive(prod)
local status, value = coroutine.resume(prod)
return value