Skip to content

Instantly share code, notes, and snippets.

View siandreev's full-sized avatar
🤔
my rubic stays cubic

Sergey Andreev siandreev

🤔
my rubic stays cubic
View GitHub Profile
@siandreev
siandreev / wallets.json
Last active May 10, 2023 08:02
Wallets list
[
{
"name": "Tonkeeper",
"image": "https://tonkeeper.com/assets/tonconnect-icon.png",
"tondns": "tonkeeper.ton",
"about_url": "https://tonkeeper.com",
"universal_url": "https://app.tonkeeper.com/ton-connect",
"bridge": [
{
"type": "sse",
@siandreev
siandreev / gist:75f1a2ccf2f3b4e2771f6089aeb06d7f
Created January 26, 2023 15:33
ton connect manifest example
{
"url": "https://ton-connect.github.io/demo-dapp/",
"name": "Demo Dapp",
"iconUrl": "https://ton-connect.github.io/demo-dapp/apple-touch-icon.png",
"termsOfUseUrl": "https://ton-connect.github.io/demo-dapp/terms-of-use.txt",
"privacyPolicyUrl": "https://ton-connect.github.io/demo-dapp/privacy-policy.txt"
}
@siandreev
siandreev / ClassDecorator.ts
Created October 20, 2021 11:39
ClassDecorator
@logClass
class Person {
public name: string;
constructor(name : string) {
this.name = name;
}
public myMethod() {
console.log('method works!');
@siandreev
siandreev / PropertyDecorator.ts
Created October 20, 2021 11:38
PropertyDecorator
function OnChange<ClassT, T>(callback: (ClassT, T) => void): any {
return (target: Object, propertyKey: string | symbol) => {
const symbolKey = Symbol(propertyKey.toString());
// Необходимо задействовать существующий дескриптор, если он есть.
// Это позволит объявять несколько декораторов на одном свойстве.
const descriptor = Object.getOwnPropertyDescriptor(target, propertyKey)
|| {configurable: true, enumerable: true};
// Подменяем или объявляем get и set
const originalGet = descriptor.get || function() {
@siandreev
siandreev / ParameterDecorator.ts
Created October 20, 2021 11:37
ParameterDecorator
class Validator {
// Map<Class.prototype, Map<MethodName, IndexesToCheck>>
private static notEmptyValidatorMap: Map<Object, Map<string, number[]>> = new Map();
static registerNotEmpty(target: Object, methodName: string, paramIndex: number): void {
let paramMap = this.notEmptyValidatorMap.get(target);
if (!paramMap) {
paramMap = new Map();
this.notEmptyValidatorMap.set(target, paramMap);
}
@siandreev
siandreev / ControllerDecorator.ts
Last active October 20, 2021 11:44
ControllerDecorator
import 'reflect-metadata';
const ControllerNameMetadataKey = Symbol('ControllerMetadata');
const ControllerMetaUrl = Symbol('ControllerMetaUrl');
function Controller(name: string) {
return function(target: Function) {
Reflect.defineMetadata(ControllerNameMetadataKey, name, target.prototype);
};
}
@siandreev
siandreev / InjectDecorator.ts
Created October 20, 2021 11:35
InjectDecorator
import 'reflect-metadata';
class Injector {
// Map<interfaceType, instance>
services: Map<Function, Object> = new Map();
registerService(interfaceType: Function, instance: Object) {
this.services.set(interfaceType, instance);
}
getService(interfaceType: Function): Object {
@siandreev
siandreev / CachingDecorator.ts
Last active October 20, 2021 11:46
Caching decorator example
class Calculator {
@Cache(200)
public add(a: number, b: number): number {
console.log('add called!')
return a + b;
}
@Cache(3000)
public sub(a: number, b: number): number {
console.log('sub called!')
@siandreev
siandreev / crypto.js
Last active May 21, 2024 17:20
Crypto price widget
// Rubic Crypto Price Widget v1.2.0
// Copyright (c) 2021 Sergey Andreev <andreev@mywish.io>
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
import Web3 from 'web3';
import dotenv from 'dotenv';
import util from "ethereumjs-util";
dotenv.config();
const rawTx = {
from: '0x83757c40420e58135d5881c0c1e30d5424462101',
gas: 100000,
to: '0xecA0A3eFCf009519052Dc92306fE821b9c7A32A2',
value: 2000,