text
stringlengths 1
1.05M
|
|---|
/**
* @license
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { AccessorContext } from './composables/useAccessor'
import type { ActiveStateContext } from './composables/useActiveState'
import type { InputStateContext } from './composables/useInputState'
import type { OptionsContext } from './composables/useOptions'
import type { SelectedStateContext } from './composables/useSelectedState'
import type { SelectProps } from './types'
import type { FocusMonitor } from '@idux/cdk/a11y'
import type { VirtualScrollInstance } from '@idux/cdk/scroll'
import type { SelectConfig } from '@idux/components/config'
import type { ComputedRef, InjectionKey, Ref, Slots } from 'vue'
export interface SelectContext
extends AccessorContext,
ActiveStateContext,
InputStateContext,
OptionsContext,
SelectedStateContext {
props: SelectProps
slots: Slots
config: SelectConfig
mergedPrefixCls: ComputedRef<string>
focusMonitor: FocusMonitor
inputRef: Ref<HTMLInputElement | undefined>
virtualScrollRef: Ref<VirtualScrollInstance | undefined>
triggerRef: Ref<HTMLDivElement | undefined>
overlayOpened: ComputedRef<boolean>
setOverlayOpened: (open: boolean) => void
handleOptionClick: (value: any) => void
}
export const selectToken: InjectionKey<SelectContext> = Symbol('selectToken')
|
function matchPlugins(plugins, requirements) {
const matchedIndices = [];
for (let i = 0; i < plugins.length; i++) {
const plugin = plugins[i];
let satisfiesRequirements = true;
for (const key in requirements) {
if (plugin[key] !== requirements[key]) {
satisfiesRequirements = false;
break;
}
}
if (satisfiesRequirements) {
matchedIndices.push(i);
}
}
return matchedIndices;
}
// Test the function with the provided example
const plugins = [
{ id: 0, name: 'Plugin A', type: 'utility', version: '1.0.0' },
{ id: 1, name: 'Plugin B', type: 'security', version: '2.1.0' },
{ id: 2, name: 'Plugin C', type: 'utility', version: '1.5.0' },
{ id: 3, name: 'Plugin D', type: 'analytics', version: '3.0.0' }
];
const requirements = { type: 'utility', version: '1.0.0' };
console.log(matchPlugins(plugins, requirements)); // Output: [0]
|
package com.bv.eidss;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import com.bv.eidss.data.EidssDatabase;
import com.bv.eidss.generated.HumanCaseSample_binding;
import com.bv.eidss.model.BaseReference;
import com.bv.eidss.model.BaseReferenceType;
import com.bv.eidss.model.CaseTypeHACode;
import com.bv.eidss.model.HumanCaseSample;
import com.bv.eidss.model.Options;
import com.bv.eidss.utils.DateHelpers;
import com.bv.eidss.utils.EidssUtils;
import java.util.List;
public class HumanCaseSampleFragment extends EidssBaseBindableFragment
implements LoaderManager.LoaderCallbacks<Cursor> {
private HumanCaseSampleActivity mActivity;
public HumanCaseSampleFragment() {
// Required empty public constructor
}
public static HumanCaseSampleFragment newInstance() {
return new HumanCaseSampleFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof Activity){
mActivity = (HumanCaseSampleActivity) context;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View v;
v = inflater.inflate(R.layout.human_case_sample_layout, container, false);
// Custom Binding
final List<String> mandatoryFields = EidssDatabase.GetMandatoryFields();
final List<String> invisibleFields = EidssDatabase.GetInvisibleFields();
EidssDatabase db = new EidssDatabase(getActivity());
Options opt = db.Options();
final long RegionDef = opt.getRegionDef();
final long RayonDef = opt.getRayonDef();
db.close();
// SampleType
LookupBind(R.id.idfsSampleType, v, mActivity.mCase.getSampleType(), mActivity.diagnosis, 0, BaseReferenceType.rftSampleType, CaseTypeHACode.HUMAN,
new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View arg1, int pos, long id) {
mActivity.mCase.setSampleType(((BaseReference) parent.getSelectedItem()).idfsBaseReference);
if (id != 0 && mActivity.mCase.getFieldCollectionDate() == null)
{
final boolean bChanged = mActivity.mCase.getChanged();
mActivity.mCase.setFieldCollectionDate(DateHelpers.Today());
DateHelpers.DisplayDate(R.id.datFieldCollectionDate, v, mActivity.mCase.getFieldCollectionDate());
if (!bChanged)
mActivity.mCase.setUnchanged();
}
}
public void onNothingSelected(AdapterView<?> arg0) {
mActivity.mCase.setSampleType(0);
}
}, true, HumanCaseSample.eidss_SampleType, mandatoryFields, invisibleFields);
// Sent To
LookupBind(R.id.idfSendToOffice, v, mActivity.mCase.getSendToOffice(), RegionDef, RayonDef, BaseReferenceType.rftInstitutionName, CaseTypeHACode.HUMAN,
new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View vw, int spnPosition, long id) {
mActivity.mCase.setSendToOffice(((BaseReference) parent.getSelectedItem()).idfsBaseReference);
}
public void onNothingSelected(AdapterView<?> parent) {
mActivity.mCase.setSendToOffice(0);
}
}, true, HumanCaseSample.eidss_SendToOffice, mandatoryFields, invisibleFields);
// End of Custom Binding
HumanCaseSample_binding.Bind(this, v, mActivity.mCase, mandatoryFields, invisibleFields, EidssUtils.getCurrentLanguage(), 0);
// hide soft keyboard
mActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
return v;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.case_toolbar, menu);
}
/* Called whenever we call invalidateOptionsMenu() */
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.Save).setVisible(false);
menu.findItem(R.id.Remove).setVisible(false);
menu.findItem(R.id.Refresh).setVisible(false);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
mActivity.Home();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return HumanCaseSample_binding.onCreateLoader(id, EidssUtils.getCurrentLanguage(), mActivity.mCase, mActivity);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
HumanCaseSample_binding.onLoadFinished(loader.getId(), data, mActivity.mCase);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
HumanCaseSample_binding.onLoaderReset(loader.getId());
}
}
|
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.camera;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;
import com.android.camera.debug.Log;
class PanoProgressBar extends ImageView {
public static final int DIRECTION_NONE = 0;
public static final int DIRECTION_LEFT = 1;
public static final int DIRECTION_RIGHT = 2;
@SuppressWarnings("unused")
private static final Log.Tag TAG = new Log.Tag("PanoProgressBar");
private final Paint mBackgroundPaint = new Paint();
private final Paint mDoneAreaPaint = new Paint();
private final Paint mIndicatorPaint = new Paint();
private float mProgress = 0;
private float mMaxProgress = 0;
private float mLeftMostProgress = 0;
private float mRightMostProgress = 0;
private float mProgressOffset = 0;
private float mIndicatorWidth = 0;
private int mDirection = 0;
private float mWidth;
private float mHeight;
private RectF mDrawBounds;
private OnDirectionChangeListener mListener = null;
public PanoProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
mDoneAreaPaint.setStyle(Paint.Style.FILL);
mDoneAreaPaint.setAlpha(0xff);
mBackgroundPaint.setStyle(Paint.Style.FILL);
mBackgroundPaint.setAlpha(0xff);
mIndicatorPaint.setStyle(Paint.Style.FILL);
mIndicatorPaint.setAlpha(0xff);
mDrawBounds = new RectF();
}
public void setOnDirectionChangeListener(OnDirectionChangeListener l) {
mListener = l;
}
public int getDirection() {
return mDirection;
}
private void setDirection(int direction) {
if (mDirection != direction) {
mDirection = direction;
if (mListener != null) {
mListener.onDirectionChange(mDirection);
}
invalidate();
}
}
@Override
public void setBackgroundColor(int color) {
mBackgroundPaint.setColor(color);
invalidate();
}
public void setDoneColor(int color) {
mDoneAreaPaint.setColor(color);
invalidate();
}
public void setIndicatorColor(int color) {
mIndicatorPaint.setColor(color);
invalidate();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mWidth = w;
mHeight = h;
mDrawBounds.set(0, 0, mWidth, mHeight);
}
public void setMaxProgress(int progress) {
mMaxProgress = progress;
}
public void setIndicatorWidth(float w) {
mIndicatorWidth = w;
invalidate();
}
public void setRightIncreasing(boolean rightIncreasing) {
if (rightIncreasing) {
mLeftMostProgress = 0;
mRightMostProgress = 0;
mProgressOffset = 0;
setDirection(DIRECTION_RIGHT);
} else {
mLeftMostProgress = mWidth;
mRightMostProgress = mWidth;
mProgressOffset = mWidth;
setDirection(DIRECTION_LEFT);
}
invalidate();
}
public void setProgress(int progress) {
// The panning direction will be decided after user pan more than 10 degrees in one
// direction.
if (mDirection == DIRECTION_NONE) {
if (progress > 10) {
setRightIncreasing(true);
} else if (progress < -10) {
setRightIncreasing(false);
}
}
// mDirection might be modified by setRightIncreasing() above. Need to check again.
if (mDirection != DIRECTION_NONE) {
mProgress = progress * mWidth / mMaxProgress + mProgressOffset;
// value bounds.
mProgress = Math.min(mWidth, Math.max(0, mProgress));
if (mDirection == DIRECTION_RIGHT) {
// The right most progress is adjusted.
mRightMostProgress = Math.max(mRightMostProgress, mProgress);
}
if (mDirection == DIRECTION_LEFT) {
// The left most progress is adjusted.
mLeftMostProgress = Math.min(mLeftMostProgress, mProgress);
}
invalidate();
}
}
public void reset() {
mProgress = 0;
mProgressOffset = 0;
setDirection(DIRECTION_NONE);
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
// the background
canvas.drawRect(mDrawBounds, mBackgroundPaint);
if (mDirection != DIRECTION_NONE) {
// the progress area
canvas.drawRect(mLeftMostProgress, mDrawBounds.top, mRightMostProgress,
mDrawBounds.bottom, mDoneAreaPaint);
// the indication bar
float l;
float r;
if (mDirection == DIRECTION_RIGHT) {
l = Math.max(mProgress - mIndicatorWidth, 0f);
r = mProgress;
} else {
l = mProgress;
r = Math.min(mProgress + mIndicatorWidth, mWidth);
}
canvas.drawRect(l, mDrawBounds.top, r, mDrawBounds.bottom, mIndicatorPaint);
}
// draw the mask image on the top for shaping.
super.onDraw(canvas);
}
public interface OnDirectionChangeListener {
public void onDirectionChange(int direction);
}
}
|
(defn find-max [arr]
(reduce #(max %1 %2) arr))
(println (find-max [3 4 7 2 1 6])) ; 7
|
<reponame>bodymovin/skia-buildbot
import '../modules/tree-scaffold-sk';
import '../modules/tree-status-sk';
import './index.scss';
|
#!/usr/bin/env bash
repoDir=$(git rev-parse --show-toplevel)
cd "$repoDir"
printf '========== flake8 ==========\n'
./tests/linters/flake.sh
printf '\n========== bandit ==========\n'
./tests/linters/bandit.sh
printf '\n========== tests ==========\n'
# https://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed
# | sed -E ':a;N;s/testing: ((\s?\S{1,}){1,})( ){2,}True\n/\1, /g;ba'
python -m unittest discover -s tests/unit
printf '\n'
read -p 'Press any key to continue'
|
import numpy as np
from scipy.integrate import quadrature
def energy_level(n):
return -13.6 / (n**2)
def weight_function(x):
return np.exp(-x)
def gaussian_quadrature_integration(func, a, b, n):
x, w = np.polynomial.legendre.leggauss(n)
integral = 0.0
for i in range(n):
integral += w[i] * func((b - a) / 2 * x[i] + (b + a) / 2)
return (b - a) / 2 * integral
def calculate_energy_levels(num_levels):
energy_levels = []
for n in range(1, num_levels + 1):
integrand = lambda x: weight_function(x) * energy_level(n)
integral, _ = quadrature(integrand, 0, np.inf)
energy_levels.append(integral)
return energy_levels
num_levels = 5
calculated_levels = calculate_energy_levels(num_levels)
print("Calculated energy levels for the first", num_levels, "energy levels:")
for i, level in enumerate(calculated_levels):
print("E_" + str(i+1) + " =", level, "electron volts")
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.