Skip to content

Instantly share code, notes, and snippets.

View rchaser53's full-sized avatar

rChaser53 rchaser53

View GitHub Profile
@rchaser53
rchaser53 / gist:279cf09a653c8ff781bf0a2f2236db62
Created October 14, 2016 14:22
redo,undoの対象がstateAなのかstateBなのか判断しなければならない例
const stateA = {
idA:{
xx:1
}
}
const stateB = {
idA:{
yy:1
}
}
@rchaser53
rchaser53 / uniontype.js
Created February 25, 2017 13:23
continueとreturnでのunion typeの挙動
// for文内のcontinueはNG
const abc = (arg: (string | number)[]) => {
for (let i=0;i<arg.length;i++) {
if (typeof arg[i] === 'string') continue;
const abc: number = arg[i];
}
}
// if文のearly returnはOK
const abc2 = (arg: (string | number)[]) => {
@rchaser53
rchaser53 / gist:39a2cdb70d97c09b7d136d8aca73dd81
Created June 1, 2017 08:56
redux-towerに使えるかな?
// redux-towerに使えるかな?
function interested(filename: string): boolean {
return filename.slice(filename.lastIndexOf('.')) === ".vue";
}
function importInterested(filename: string): boolean {
return interested(filename) && filename.slice(0, 2) === "./";
}
|hoge|
hoge := array collect: [ :elem |
| dict |
dict := Dictionary new.
dict at: #base put: elem.
dict at: #translated put: (self trans: elem).
dict
].
hoge := hoge asOrderedCollection
@rchaser53
rchaser53 / gist:7e63a93678821b03258bfd9b0dfe7da3
Last active December 22, 2017 03:08
async/await and return
async function waitAndMaybeReject() {
// Wait one second
await new Promise(r => setTimeout(r, 1000));
// Toss a coin
const isHeads = Boolean(Math.round(Math.random()));
if (isHeads) return 'yay'; // comment out when error
throw Error('Boo!');
}
@rchaser53
rchaser53 / borrow.rs
Created December 16, 2018 13:58
situation for borrow
foo(&i);
foo(&mut i);
fn foo<T: Borrow<i32> + Display>(a: T) {
println!("a is borrowed: {}", a);
}
@rchaser53
rchaser53 / 031119_how_to_avoid_error
Created March 10, 2019 15:11
now vue press emits error when executes 'vuepress dev'
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "vuepress dev"
},
"keywords": [],
"author": "",
const promiseFunc = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, 2000)
})
}
const forEachAsync = () => {
[1, 2, 3, 4, 5].forEach(async (index) => {
@rchaser53
rchaser53 / playground.rs
Created January 22, 2020 11:55
Code shared from the Rust Playground
fn main() {
println!("Hello, world!");
}
@rchaser53
rchaser53 / playground.rs
Created January 22, 2020 14:46
Code shared from the Rust Playground
extern {
pub static lorem: c_int;
}