Skip to content

Instantly share code, notes, and snippets.

View shikelong's full-sized avatar
🏠
Working from home

shikelong shikelong

🏠
Working from home
View GitHub Profile
@shikelong
shikelong / convert-file-name.rb
Created November 17, 2021 01:25
【Ruby】 Convert file name (a b.svg ==> a-b.svg)
puts "start convert file names to hyphen style...."
def traverse_dir(fileType)
folder_path = File.absolute_path("./") + "/"
scheme = folder_path + "*.#{fileType}"
puts "find #{Dir.glob(scheme).length} #{fileType} files, start convert...."
puts '-' * 50
Dir.glob(scheme).each do |f|
filename = File.basename(f, File.extname(f))
File.rename(f, folder_path + filename.downcase.tr(' ', '-') + File.extname(f))
@shikelong
shikelong / useInfiniteQuery.ts
Created November 15, 2021 08:13
[rtk query] useInfiniteQuery
import { QueryDefinition } from "@reduxjs/toolkit/dist/query";
import {
LazyQueryTrigger,
QueryHooks,
} from "@reduxjs/toolkit/dist/query/react/buildHooks";
import { useEffect, useState } from "react";
type GetResultTypeFromEndpoint<Endpoint> = Endpoint extends QueryHooks<
QueryDefinition<any, any, string, infer ResultType, string>
>
@shikelong
shikelong / checksession.html
Created November 12, 2021 04:11
check session example
<!DOCTYPE html>
<!--Copyright (c) Brock Allen & Dominick Baier. All rights reserved.-->
<!--Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.-->
<html>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=edge' />
<title>Check Session IFrame</title>
</head>
<body>
const {PNG} = require('bundle.js');
const {Button, ImageView, ui} = require('tabris');
const base64 = require('base-64');
function _arrayBufferToBase64( buffer ) {
var binary = '';
var bytes = new Uint8Array( buffer );
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
@shikelong
shikelong / useControlledState
Created September 16, 2021 05:36
Hook help write Controlled Component Pattern
import * as React from 'react';
export default function useControlledState<T, R = T>(
defaultStateValue: T | (() => T),
option?: {
defaultValue?: T | (() => T);
value?: T;
onChange?: (value: T, prevValue: T) => void;
postState?: (value: T) => T;
}
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 -->
<html lang="zh-cmn-Hans"> <!-- 更加标准的 lang 属性写法 http://zhi.hu/XyIa -->
<head>
<!-- 声明文档使用的字符编码 -->
<meta charset='utf-8'>
<!-- 优先使用 IE 最新版本和 Chrome -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<!-- 页面描述 -->
<meta name="description" content="不超过150个字符"/>
<!-- 页面关键词 -->
import * as React from 'react';
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import { shallow, mount, render } from 'enzyme';
import {Home} from '../src/common/components/home/Home';
import {AxiosApi} from 'some-package'
import { Provider } from 'react-redux';
import MockAdapter from 'axios-mock-adapter';
@shikelong
shikelong / setting.json
Last active October 11, 2021 01:19
Windows Terminal Setting Configuration
{
"$schema": "https://aka.ms/terminal-profiles-schema",
// Add custom actions and keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
"actions":
[
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
@shikelong
shikelong / get-sharepoint-access-token.py
Created November 11, 2020 08:50 — forked from demelziraptor/get-sharepoint-access-token.py
Code example to get a Sharepoint Access Token to use with the Sharepoint REST API using a python 3 provider-hosted Sharepoint App (using cherrypy). This code takes the data POSTed to it when you click on the app in Sharepoint, and authenticates using OAuth to get the access token. To use the Sharepoint REST API with OAuth, the app needs to be re…
import cherrypy
import jwt
import urllib.parse, urllib.request
import json
SPSECRET = 'gpYucHkODHOv6JxZJ89Kihl9ncTiTrUCAbOaF1N6uJE='
cherrypy.config.update({'server.socket_port': 3005,
'server.ssl_module': 'builtin',
'server.ssl_certificate': 'cert.pem',
@shikelong
shikelong / Demo.js
Last active December 15, 2020 01:21
VideoPlay History
recordVideoPlayHistory('testVideo', {
"EmailOrUserName": "[email protected]",
"WatchTokenOrPwd":"ayr1",
"LoginToken": "C52AC508-8778-E5FC-95F3-35DDDB21BBC1",
"UserType": 1
}, guid(), 7);