text:
package net.coding.program.common;

import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.Spannable;
import android.text.style.ImageSpan;
import android.text.style.QuoteSpan;
import android.text.style.URLSpan;
import android.view.View;

import net.coding.program.common.enter.GifImageSpan;
import net.coding.program.common.htmltext.GrayQuoteSpan;
import net.coding.program.common.model.AccountInfo;
import net.coding.program.route.URLSpanNoUnderline;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import pl.droidsonroids.gif.GifDrawable;

/**
 * Created by chenchao on 2017/11/22.
 */
public class GlobalCommon {

    public static Map<String, Class<?>> rounterMap = new HashMap<>();
    public static String ROUNTER_2FA = "ROUNTER_2FA";
    public static String ROUNTER_AUTH_LIST = "ROUNTER_AUTH_LIST";

    public static View.OnClickListener clickJumpWebView;
    public static View.OnClickListener mOnClickUser;

    public static int dpToPx(int dpValue) {
        return (int) (dpValue * GlobalData.sScale + 0.5f);
    }

    public static int dpToPx(double dpValue) {
        return (int) (dpValue * GlobalData.sScale + 0.5f);
    }

    public static int pxToDp(float pxValue) {
        return (int) (pxValue / GlobalData.sScale + 0.5f);
    }

    public static void start2FAActivity(Activity activity) {
        Intent intent;
        if (AccountInfo.loadAuthDatas(activity).isEmpty()) {
            intent = new Intent(activity, rounterMap.get(ROUNTER_2FA));
        } else {
            intent = new Intent(activity, rounterMap.get(ROUNTER_AUTH_LIST));
        }

        activity.startActivity(intent);
    }

    public static Spannable changeHyperlinkColor(String content) {
        return changeHyperlinkColor(content, null, null);
    }

    public static Spannable changeHyperlinkColor(String content, MyImageGetter imageGetter) {
        return changeHyperlinkColor(content, imageGetter, null);
    }

    public static Spannable changeHyperlinkColor(String content, int linkColor) {
        return changeHyperlinkColor(content, null, Global.tagHandler, linkColor);
    }

    public static Spannable changeHyperlinkColor(String content, int color, MyImageGetter imageGetter) {
        return changeHyperlinkColor(content, imageGetter, null, color);
    }

    public static Spannable changeHyperlinkColor(String content, Html.ImageGetter imageGetter, Html.TagHandler tagHandler) {
        return changeHyperlinkColor(content, imageGetter, tagHandler, CodingColor.select2);
    }

    public static Spannable changeHyperlinkColorMaopao(String content, Html.ImageGetter imageGetter, Html.TagHandler tagHandler, AssetManager assetManager) {
        Spannable s = changeHyperlinkColor(content, imageGetter, tagHandler, CodingColor.select2);
        return spannToGif(s, assetManager);
    }

    public static Spannable changeHyperlinkColor(String content, Html.ImageGetter imageGetter, Html.TagHandler tagHandler, int color) {
        Spannable s = (Spannable) Html.fromHtml(content, imageGetter, tagHandler);
        return getCustomSpannable(color, s);
    }

    static Spannable getCustomSpannable(int color, Spannable s) {
        URLSpan[] urlSpan = s.getSpans(0, s.length(), URLSpan.class);
        for (URLSpan span : urlSpan) {
            int start = s.getSpanStart(span);
            int end = s.getSpanEnd(span);
            s.removeSpan(span);
            span = new URLSpanNoUnderline(span.getURL(), color);
            s.setSpan(span, start, end, 0);
        }

        QuoteSpan quoteSpans[] = s.getSpans(0, s.length(), QuoteSpan.class);
        for (QuoteSpan span : quoteSpans) {
            int start = s.getSpanStart(span);
            int end = s.getSpanEnd(span);
            s.removeSpan(span);
            GrayQuoteSpan grayQuoteSpan = new GrayQuoteSpan();
            s.setSpan(grayQuoteSpan, start, end, 0);
        }

        return s;
    }

    public static Spannable recentMessage(String content, Html.ImageGetter imageGetter, Html.TagHandler tagHandler) {
        String parse = HtmlContent.parseToText(content);

        Spannable s = (Spannable) Html.fromHtml(parse, imageGetter, null);
        return GlobalCommon.getCustomSpannable(CodingColor.font3, s);
    }

    private static Spannable spannToGif(Spannable s, AssetManager assetManager) {
        ImageSpan[] imageSpans = s.getSpans(0, s.length(), ImageSpan.class);

        final String[] gifEmojiName = new String[]{
                "festival-emoji-01.gif",
                "festival-emoji-02.gif",
                "festival-emoji-03.gif",
                "festival-emoji-04.gif",
                "festival-emoji-05.gif",
                "festival-emoji-06.gif",
                "festival-emoji-07.gif",
                "festival-emoji-08.gif",
        };

        for (ImageSpan imageSpan : imageSpans) {
            int start = s.getSpanStart(imageSpan);
            int end = s.getSpanEnd(imageSpan);

            String imageSource = imageSpan.getSource();
            for (String endString : gifEmojiName) {
                if (imageSource.endsWith(endString)) {
                    try {
                        GifDrawable gifDrawable = new GifDrawable(assetManager, endString);
                        zoomDrwable(gifDrawable, true);
                        gifDrawable.setLoopCount(100);
                        GifImageSpan gifImageSpan = new GifImageSpan(gifDrawable);
                        s.removeSpan(imageSpan);
                        s.setSpan(gifImageSpan, start, end, 0);
                    } catch (Exception e) {
                        Global.errorLog(e);
                    }
                }
            }
        }

        return s;
    }

    // todo 删除
    public static void zoomDrwable(Drawable drawable, boolean isMonkey) {
        int width = isMonkey ? GlobalData.sEmojiMonkey : GlobalData.sEmojiNormal;
        drawable.setBounds(0, 0, width, width);
    }

    public static String mbToRmb(BigDecimal point) {
        String rmbString = String.valueOf(point.multiply(new BigDecimal(50)));
        if (rmbString.endsWith(".00")) {
            rmbString = rmbString.substring(0, rmbString.length() - 3);
        } else if (rmbString.endsWith(".0")) {
            rmbString = rmbString.substring(0, rmbString.length() - 2);
        }
        return "¥" + rmbString;
    }
}


text:
require "spec_helper"

RSpec.describe Keisan::Context do
  it "contains function and variable registries" do
    my_context = described_class.new

    my_context.register_variable!("x", 2)
    my_context.register_function!("f", Proc.new {|x| x**2})
    expect(my_context.variable("x").value).to eq 2
    expect(my_context.function("f").call(nil, 3).value).to eq 9
  end

  it "has default variables and functions" do
    my_context = described_class.new

    expect(my_context.variable("PI").value).to eq Math::PI
    expect(my_context.function("sin")).to be_a(Keisan::Function)
  end

  describe "freeze" do
    it "freezes associated registries" do
      frozen_context = described_class.new
      frozen_context.register_variable!("x", 1)
      frozen_context.register_function!("f", Proc.new {|x| x})
      frozen_context.freeze

      expect{frozen_context.register_variable!("x", 10)}.to raise_error(Keisan::Exceptions::UnmodifiableError)
      expect{frozen_context.register_function!("f", Proc.new {|x| x**2})}.to raise_error(Keisan::Exceptions::UnmodifiableError)

      child_context = frozen_context.spawn_child
      child_context.register_variable!("x", 2)
      child_context.register_function!("f", Proc.new {|x| 2*x})

      expect(frozen_context.variable("x").value).to eq 1
      expect(child_context.variable("x").value).to eq 2

      expect(frozen_context.function("f").call(nil, 3).value).to eq 3
      expect(child_context.function("f").call(nil, 3).value).to eq 6
    end

    it "works on list/hash variables" do
      calculator = Keisan::Calculator.new
      calculator.evaluate("x = [1, [2,3], {'a': 10, 'b': 20}]")
      calculator.evaluate("y = {'alpha': 6, 'beta': [7,7,7], 'gamma': {'foo': 100}}")

      # Can modify list no problem
      calculator.evaluate("x[0] += 10")
      calculator.evaluate("x[1][0] += 10")
      calculator.evaluate("x[2]['a'] += 10")
      expect(calculator.evaluate("x")).to eq([11, [12,3], {"a" => 20, "b" => 20}])

      # Can modify hash no problem
      calculator.evaluate("y['alpha'] += 10")
      calculator.evaluate("y['beta'][0] += 10")
      calculator.evaluate("y['gamma']['foo'] += 10")
      expect(calculator.evaluate("y")).to eq({"alpha" => 16, "beta" => [17,7,7], "gamma" => {"foo" => 110}})

      # Freeze
      calculator.context.freeze

      # Can still access the values
      expect(calculator.evaluate("x[0]")).to eq(11)
      expect(calculator.evaluate("y['alpha'] + 2")).to eq(18)

      child_calculator = Keisan::Calculator.new(context: calculator.context.spawn_child)
      child_calculator.evaluate("z = y['gamma']['foo'] * 3")
      expect(child_calculator.evaluate("z")).to eq(330)

      # But can no longer modify
      expect{calculator.evaluate("x[0] += 10")}.to raise_error(Keisan::Exceptions::UnmodifiableError)
      expect{calculator.evaluate("x[1][0] = 10")}.to raise_error(Keisan::Exceptions::UnmodifiableError)
      expect{calculator.evaluate("x[2]['a'] += 10")}.to raise_error(Keisan::Exceptions::UnmodifiableError)
      expect{calculator.evaluate("x = 10")}.to raise_error(Keisan::Exceptions::UnmodifiableError)

      expect{calculator.evaluate("y['alpha'] += 10")}.to raise_error(Keisan::Exceptions::UnmodifiableError)
      expect{calculator.evaluate("y['beta'][0] += 10")}.to raise_error(Keisan::Exceptions::UnmodifiableError)
      expect{calculator.evaluate("y['gamma']['foo'] += 10")}.to raise_error(Keisan::Exceptions::UnmodifiableError)
      expect{calculator.evaluate("y = 10")}.to raise_error(Keisan::Exceptions::UnmodifiableError)
    end
  end

  describe "spawn_child" do
    it "has parent context's variables and functions" do
      my_context = described_class.new

      my_context.register_variable!("x", 2)
      my_context.register_function!("f", Proc.new {|x| x**2})

      child_context = my_context.spawn_child
      expect(child_context.variable("x").value).to eq 2
      expect(child_context.function("f").call(nil, 3).value).to eq 9
    end

    it "can override parent with new definitions" do
      my_context = described_class.new

      my_context.register_variable!("x", 2)
      my_context.register_variable!("y", 7)
      my_context.register_function!("f", Proc.new {|x| x**2})
      my_context.register_function!("g", Proc.new {|x| x-1})

      child_context = my_context.spawn_child
      child_context.register_variable!("x", 5)
      child_context.register_variable!("z", 9)
      child_context.register_function!("f", Proc.new {|x| x**3})
      child_context.register_function!("h", Proc.new {|x| x**4})

      expect(my_context.variable("x").value).to eq 5 # Updated in child
      expect(my_context.variable("y").value).to eq 7
      expect{my_context.variable("z").value}.to raise_error(Keisan::Exceptions::UndefinedVariableError)
      expect(my_context.function("f").call(nil, 2).value).to eq 8 # Updated in child
      expect(my_context.function("g").call(nil, 2).value).to eq 1
      expect{my_context.function("h").value}.to raise_error(Keisan::Exceptions::UndefinedFunctionError)

      expect(child_context.variable("x").value).to eq 5
      expect(child_context.variable("y").value).to eq 7
      expect(child_context.variable("z").value).to eq 9
      expect(child_context.function("f").call(nil, 2).value).to eq 8
      expect(child_context.function("g").call(nil, 2).value).to eq 1
      expect(child_context.function("h").call(nil, 2).value).to eq 16
    end

    it "can hide parent variables with shadowed argument" do
      my_context = described_class.new

      my_context.register_variable!("x", 2)
      my_context.register_variable!("y", 7)

      child_context = my_context.spawn_child(shadowed: ["x"])

      expect(my_context.variable("x").value).to eq 2
      expect(my_context.variable("y").value).to eq 7
      expect{child_context.variable("x").value}.to raise_error(Keisan::Exceptions::UndefinedVariableError)
      expect(child_context.variable("y").value).to eq 7

      child_context.register_variable!("x", 13)
      expect(child_context.variable("x").value).to eq 13
    end
  end

  describe "random" do
    it "uses given Random object" do
      context1 = described_class.new(random: Random.new(1234))
      context2 = described_class.new(random: Random.new(1234))

      20.times do
        expect(context1.random.rand(100)).to eq context2.random.rand(100)
      end
    end

    it "uses parent random if does not have one" do
      rand1 = Random.new(2244)
      rand2 = Random.new(2244)

      parent = described_class.new(random: rand1)
      child  = described_class.new(parent: parent)

      20.times do
        expect(child.random.rand(100)).to eq rand2.rand(100)
      end
    end

    it "it shadows the parent random" do
      rand1 = Random.new(5151)
      rand1_copy = Random.new(5151)
      rand2 = Random.new(5959)

      parent = described_class.new(random: rand1)
      child  = described_class.new(parent: parent, random: rand2)

      matches = 20.times.map do |_|
        child.random.rand(100) == rand1_copy.rand(100)
      end

      expect(matches.any? {|bool| bool == false}).to be true
    end

    it "has the random object set once and only once" do
      context = described_class.new
      random = context.random
      expect(random).to eq context.random
    end

    it "can be set to override existing internal random object" do
      rand1 = Random.new(2244)
      rand1_copy = Random.new(2244)
      rand2 = Random.new(4466)

      context = described_class.new(random: rand2)
      context.set_random(rand1_copy)

      20.times do
        expect(context.random.rand(100)).to eq rand1.rand(100)
      end
    end
  end

  describe "has_variable?" do
    let(:context) { described_class.new }

    it "returns true of variable is defined" do
      expect(context.has_variable?("PI")).to eq true
      expect(context.has_variable?("not_exist")).to eq false
      context.register_variable!("not_exist", 5)
      expect(context.has_variable?("not_exist")).to eq true
    end
  end

  describe "has_function?" do
    let(:context) { described_class.new }

    it "returns true of function is defined" do
      expect(context.has_function?("sin")).to eq true
      expect(context.has_function?("not_exist")).to eq false
      context.register_function!("not_exist", Proc.new { nil })
      expect(context.has_function?("not_exist")).to eq true
    end
  end

  describe "transient context" do
    it "has parent context's variables and functions" do
      my_context = described_class.new

      my_context.register_variable!("x", 2)
      my_context.register_function!("f", Proc.new {|x| x**2})

      child_context = my_context.spawn_child(transient: true)
      expect(child_context.variable("x").value).to eq 2
      expect(child_context.function("f").call(nil, 3).value).to eq 9
    end

    it "can be overridden" do
      my_context = described_class.new

      my_context.register_variable!("x", 2)
      my_context.register_function!("f", Proc.new {|x| x**2})

      transient_context = my_context.spawn_child(transient: true)
      nontransient_context = transient_context.spawn_child(transient: false)

      transient_context.register_variable!("x", 3)
      expect(my_context.variable("x").value).to eq 3

      nontransient_context.register_variable!("x", 5)
      expect(my_context.variable("x").value).to eq 5 # Bubbled up
      expect(nontransient_context.variable("x").value).to eq 5
    end

    it "is transient so all definitions bubble up to parent context" do
      my_context = described_class.new

      my_context.register_variable!("x", 2)
      my_context.register_variable!("y", 7)
      my_context.register_function!("f", Proc.new {|x| x**2})
      my_context.register_function!("g", Proc.new {|x| x-1})

      expect(my_context.variable("x").value).to eq 2
      expect(my_context.variable("y").value).to eq 7
      expect(my_context.function("f").call(nil, 2).value).to eq 4
      expect(my_context.function("g").call(nil, 2).value).to eq 1

      child_context = my_context.spawn_child(transient: true)

      expect(my_context.transient?).to be false
      expect(child_context.transient?).to be true

      child_context.register_variable!("x", 5)
      child_context.register_function!("f", Proc.new {|x| x**3})
      Keisan::Calculator.new(context: child_context).evaluate("y = 11")
      Keisan::Calculator.new(context: child_context).evaluate("g(x) = 123*x")

      # Overriden by transient child!
      expect(my_context.variable("x").value).to eq 5
      expect(my_context.variable("y").value).to eq 11
      expect(my_context.function("f").call(nil, 2).value).to eq 8
      expect(my_context.function("g").call(nil, 2).value).to eq 246

      expect(child_context.variable("x").value).to eq 5
      expect(child_context.variable("y").value).to eq 11
      expect(child_context.function("f").call(nil, 2).value).to eq 8
      expect(child_context.function("g").call(nil, 2).value).to eq 246
    end

    it "stores transient definitions" do
      my_context     = described_class.new
      child_context  = my_context.spawn_child(definitions: {x: 15, f: Proc.new {|x| x**2}}, transient: true)
      child2_context = child_context.spawn_child(definitions: {y: 32, g: Proc.new {|x| x**3}}, transient: true)

      expect(child_context.transient_definitions.keys).to match_array(["x", "f"])
      expect(child2_context.transient_definitions.keys).to match_array(["x", "y", "f", "g"])
    end

    it "inherits transientness from parent" do
      my_context     = described_class.new
      child_context  = my_context.spawn_child(definitions: {x: 15, f: Proc.new {|x| x**2}}, transient: true)
      child2_context = child_context.spawn_child(definitions: {y: 32, g: Proc.new {|x| x**3}})

      expect(child_context.transient_definitions.keys).to match_array(["x", "f"])
      expect(child2_context.transient_definitions.keys).to match_array(["x", "y", "f", "g"])

      expect{my_context.variable("x")}.to raise_error(Keisan::Exceptions::UndefinedVariableError)
      child2_context.register_variable!("x", 123)
      expect(my_context.variable("x").value).to eq 123
    end
  end

  describe "local variables/functions" do
    context "variables" do
      it "does not bubble up to definition defined at parent context" do
        parent = described_class.new
        child  = parent.spawn_child(transient: false)

        parent.register_variable!("x", 1)
        child.register_variable!("x", 2)

        expect(parent.variable("x").value).to eq 2

        child.register_variable!("x", 3, local: true)

        expect(parent.variable("x").value).to eq 2
        expect(child.variable("x").value).to eq 3
      end
    end

    context "functions" do
      it "does not bubble up to definition defined at parent context" do
        parent = described_class.new
        child  = parent.spawn_child(transient: false)

        parent.register_function!("f", Proc.new {|x| 1})
        child.register_function!("f", Proc.new {|x| 2})

        expect(parent.function("f").call(nil, 100).value).to eq 2

        child.register_function!("f", Proc.new {|x| 3}, local: true)

        expect(parent.function("f").call(nil, 100).value).to eq 2
        expect(child.function("f").call(nil, 100).value).to eq 3
      end
    end
  end
end

redpajama_set_name: RedPajamaGithub


text:
<link rel="stylesheet" href="hv-sidebar.css">

<template id='hv-sidebar'>

{{channel}}

            <button id='writeHV' class='btn btn-info disabled' onclick='writeHV()'>Write HV</button>
            <button id='abortHVupdate' class='btn btn-danger disabled' onclick='abortHV()'>Abort Update</button>

            Channel Bias:

                    <input value="true" name="HVbias" id="HVon" type="radio" onchange='demandHVwrite()'></input>
                    On

                    <input value="false" name="HVbias" id="HVoff" type="radio" onchange='demandHVwrite()'></input>
                    Off

            Demand Voltage
            <input id='demandVoltageSlide' type='range' min='0' step='1' onchange='demandHVwrite()' oninput='reportHVdemand()'></input>

</template>


text:
package de.peeeq.wurstscript.gui;

public class WurstGuiLogger extends WurstGui {

	@Override
	public void sendProgress(String whatsRunningNow, double percent) {
		// ignore
	}

	@Override
	public void sendFinished() {
		// ignore
	}

	@Override
	public void showInfoMessage(String message) {
		System.out.println(message);
	}

}


text:
import '@angular/platform-browser';
import '@angular/core';
import '@angular/http';
import '@angular/router';

// RxJS
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';

import 'jquery';
import 'jquery-ui/ui/widgets/datepicker';
import 'jquery-ui-timepicker-addon';
import 'bootstrap';
// import 'bootstrap-loader';

import 'leaflet';

import 'x2js';


text:
module LinearIsotropicMod

import Base.copy

# Function sto extend
import FEM: create_matstat, stiffness, stress

# Types needed
import FEM: AbstractMaterialStatus, AbstractMaterial, GaussPoint2

export LinearIsotropicMS, LinearIsotropic

immutable LinearIsotropicMS <:AbstractMaterialStatus
    strain::Vector{Float64}
    stress::Vector{Float64}
end

LinearIsotropicMS() = LinearIsotropicMS(zeros(6), zeros(6))

copy(matstat::LinearIsotropicMS) = LinearIsotropicMS(copy(matstat.strain), copy(matstat.stress))

type LinearIsotropic <: AbstractMaterial
    E::Float64
    ν::Float64
    G::Float64
    k::Matrix{Float64}
    σ::Vector{Float64}
end

function LinearIsotropic(E, ν)
    G = E / (2 * (1 + ν))
    f = E / ((1.0 + ν) * (1.0 - 2.0 * ν))

    k = zeros(4, 4)

    k[1, 1] = k[2, 2] = k[3, 3] = f * (1.0 - ν)
    k[4, 4]  = G

    # Off diagonals
    k[1, 2] = k[1, 3] = k[2, 1] = k[2, 3] = k[3, 1] = k[3, 2] = f * ν

    LinearIsotropic(E, ν, G, k, zeros(4))
end

stiffness(mat::LinearIsotropic, ::GaussPoint2) = mat.k

create_matstat(::Type{LinearIsotropic}) = LinearIsotropicMS()

function stress(mat::LinearIsotropic, ɛ::Vector{Float64}, gp::GaussPoint2)
    D = stiffness(mat, gp)
    # TODO: Unroll this matrix multiplication
    A_mul_B!(mat.σ, D, ɛ)
    return mat.σ
end

end


text:
namespace SupermarketChain.Model
{
    using System.Collections.Generic;

    public class Product
    {
        private ICollection<Sale> sales;

        public Product()
        {
            this.sales = new HashSet<Sale>();
        }

        public int Id { get; set; }

        public string Name { get; set; }

        public decimal Price { get; set; }

        public virtual Vendor Vendor { get; set; }

        public int VendorId { get; set; }

        public virtual Measure Measure { get; set; }

        public int MeasureId { get; set; }

        public virtual ICollection<Sale> Sales
        {
            get { return this.sales; }
            set { this.sales = value; }
        }
    }
}


text:
import { DefaultElements, MakeRequest } from '../common-types';
export declare type AssetKeyProps = {
    /** A JWT describing a policy; needs to be attached to signed URLs */
    policy: string;
    /** A secret key to be used for signing URLs */
    secret: string;
};
export declare type CreateAssetKeyProps = {
    /** (required) UNIX timestamp in the future (but not more than 48 hours from now) */
    expiresAt: number;
};
export interface AssetKey extends AssetKeyProps, DefaultElements<AssetKeyProps> {
}
/**
 * @private
 * @param http - HTTP client instance
 * @param data - Raw asset key data
 * @return Wrapped asset key data
 */
export declare function wrapAssetKey(_makeRequest: MakeRequest, data: AssetKeyProps): AssetKey;