Skip to content

Instantly share code, notes, and snippets.

View xiaoyvr's full-sized avatar

Yu Xiaoqiang xiaoyvr

  • ThoughtWorks
  • Dallas
View GitHub Profile
function include($dep){
if(-not $__includeContainer){
$__includeContainer = New-Object "system.collections.generic.hashset[string]"
}
$folder = Split-Path $MyInvocation.ScriptName -Parent
$searchPaths = $folder, $__searchPaths
foreach($path in $searchPaths){
if(Test-Path "$path\$dep.ps1"){
$file = "$path\$dep.ps1"
@xiaoyvr
xiaoyvr / DSL of setValueOf
Last active December 22, 2015 00:38
DSL of setValueOf
function setValueOf(fieldName, obj) {
var originVal = obj[fieldName] || {};
var getters = [];
var builder = {
inRange: function (collection, findKey) {
getters.push(function () {
return _.find(collection, function (i) {
return findKey ? (i[findKey] === originVal[findKey]) : (i === originVal);
});
});
require 'formula'
class Solfege < Formula
homepage 'http://www.solfege.org/'
url 'http://ftpmirror.gnu.org/solfege/solfege-3.22.2.tar.xz'
mirror 'http://ftp.gnu.org/gnu/solfege/solfege-3.22.2.tar.xz'
sha1 '060cf7975e17f3d696acd1dfc8676703be7c7ffa'
depends_on "pkg-config" => :build
depends_on "gettext" => :build
@xiaoyvr
xiaoyvr / ed2k-pp
Created December 9, 2014 16:39
extract ed2k links from pp
Array.join($('a[data-href^="ed2k"]').map(function(){return $(this).attr('data-href')}), '\n');
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.ComponentModel;
using System.Threading;
namespace testdynamic
{
/// <summary>
@xiaoyvr
xiaoyvr / Either.cs
Created October 24, 2016 08:47 — forked from siliconbrain/Either.cs
Implemetation of Haskell's Either type in C#
/// <summary>
/// Interface definition of Either
/// </summary>
/// <typeparam name="Tl">type of the Left value</typeparam>
/// <typeparam name="Tr">type of the Right value</typeparam>
public interface IEither<out Tl, out Tr>
{
/// <summary>
/// Check the type of the value held and invoke the matching handler function
/// </summary>
@xiaoyvr
xiaoyvr / CSG-revision.go
Created July 26, 2017 15:25
how couchbase sync gateway generate the document revision id
func createRevID(generation int, parentRevID string, body Body) string {
// This should produce the same results as TouchDB.
digester := md5.New()
digester.Write([]byte{byte(len(parentRevID))})
digester.Write([]byte(parentRevID))
digester.Write(canonicalEncoding(stripSpecialProperties(body)))
return fmt.Sprintf("%d-%x", generation, digester.Sum(nil))
}
@xiaoyvr
xiaoyvr / Microsoft.PowerShell_profile.ps1
Last active November 1, 2017 11:49
get windows laptop work without admin priviledge
$path = $env:PATH
$excludes = @('C:\Program Files\nodejs\', 'C:\Program Files\Git\cmd', 'C:\Program Files (x86)\Yarn\bin')
$path = ($path.Split(';') | Where-Object {
-not $excludes.contains($_)
}) -join ';'
$env:PATH = "C:\Program Files (x86)\Microsoft VS Code\bin;$path"

First step

find the language settings, reset the hotkey as NotAssigned instead of (`)

things need to do with admin access

  • install docker (need logout, need restart when install hyper-v)
  • uninstall chrome
  • uninstall git, nodejs if they are installed as admin user.

install chrome with user privilege

Manage Node Version in Windows

Require scoop to be installed. Then put these in your $profile, you will get different nodejs for different powershell session.

function Set-LocationWithNodeVersion ($dir){
	Set-Location $dir
	if (Test-Path '.\package.json') {
		$json = Get-Content '.\package.json' | ConvertFrom-Json
		$version = $json.engines.node