Skip to content

Instantly share code, notes, and snippets.

View caoyue's full-sized avatar
😓
I may be slow to respond.

caoyue caoyue

😓
I may be slow to respond.
View GitHub Profile
@caoyue
caoyue / dos2unix.ps1
Created June 26, 2017 17:26
dos2unix and unix2dos powershell script
function Convert-Files($source, $dest) {
Get-ChildItem -File -Recurse |
Where-Object {$_.extension -match "^.(py|js|css|html)$"} |
ForEach-Object {
Convert-File $_.FullName $source $dest
}
}
function Convert-File($path, $source, $dest) {
@caoyue
caoyue / gh.ps1
Last active October 21, 2021 12:26
open git host url for current repository with browser in powershell
function Open-GitWeb {
$r = git remote -v | Select-String -Pattern "(https:\/\/|git@)(?<git>.*)\.git"
if ($r.Matches.Length -gt 0) {
$t = "https://" + ($r.Matches[0].Groups |
Where-Object {$_.Name -eq "git"}).Value.Replace(":", "/")
Write-Host "gh: openning ",$t,"..." -ForegroundColor "green"
Start-Process $t
}
else
cat base64.txt | base64 --decode > enc.bin
openssl aes-256-cbc -d -in enc.bin -out source.txt
class Solution:
# @param {integer} n
# @return {integer}
def countPrimes(self, n):
if n < 3:
return 0
sieve = [True] * (n / 2)
for i in xrange(3, int(n ** 0.5) + 1, 2):
if sieve[i / 2]:
sieve[i * i / 2::i] = [False] * ((n - i * i - 1) / (2 * i) + 1)
@caoyue
caoyue / pascal.cs
Created June 18, 2015 03:28
Pascal's Triangle
using System;
using System.Collections.Generic;
using System.Linq;
namespace TestConsole
{
public class Program
{
public static void Main(string[] args)
{
@caoyue
caoyue / fword.erl
Created June 10, 2015 07:43
erlang first word
-module(test).
-export([do/0]).
do() ->
first_word_bin(<<"some words">>).
first_word_bin(Bin) ->
first_word_bin(ltrim(Bin), <<>>).
% <<"some">>
@caoyue
caoyue / parse_url.js
Last active August 29, 2015 14:22
js parse url
function parseURL(url){
var parse_url = /^(?:([A-Za-z]+):(\/{0,3}))?([0-9.\-A-Za-z]+\.[0-9A-Za-z]+)?(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
var names = ['url', 'scheme', 'slash', 'host', 'port', 'path', 'query', 'hash'];
var results = parse_url.exec(url);
var that = {};
for (var i = 0, len = names.length; i < len; i += 1) {
that[names[i]] = results[i] || '';
}
return that;
}
@caoyue
caoyue / md5.cs
Last active August 29, 2015 14:22
using System;
using System.Text;
using System.Security.Cryptography;
public class Program
{
public static void Main()
{
Console.WriteLine(Encrypt("123456"));
// CE0BFD15059B68D67688884D7A3D3E8C
@caoyue
caoyue / test.erl
Last active August 29, 2015 14:21
create a function that converts a proplists to record with macro
-module(test).
-export([do/0]).
-define(fuxk(Record, Val),
fun() ->
list_to_tuple([Record | [get(X,Val) || X <- record_info(fields, Record)]])
end
).
-record(test, {
# -*- coding: utf-8 -*-
import urllib2
from multiprocessing import Pool
from multiprocessing.dummy import Pool as ThreadPool
def create_urls():
return ["http://www.baidu.com/%s" % i for i in xrange(100)]