Skip to content

Instantly share code, notes, and snippets.

View vgrichina's full-sized avatar

Vladimir Grichina vgrichina

View GitHub Profile
data Rope = Empty | Concat Int Rope Rope | Leaf String deriving (Show, Eq)
rope :: String -> Rope
rope "" = Empty
rope s = Leaf s
len :: Rope -> Int
len Empty = 0
len (Leaf s) = length s
len (Concat length _ _) = length
@vgrichina
vgrichina / SQLServerDialect.java
Created November 3, 2009 22:51
Improved MSSQL dialect for Hibernate (using more appropriate data types)
/*
* Copyright © 2009, Componentix. All rights reserved.
*/
package com.componentix.hibernate.dialect;
import java.sql.Types;
/**
* A proper dialect for Microsoft SQL Server 2000 and 2005.
@vgrichina
vgrichina / NSObject+KVOWeakPropertyDebug.h
Created January 12, 2013 01:09
NSObject category that logs calls to addObserver for weak properties (as they aren't fully KVO-compliant)
//
// NSObject+KVOWeakPropertyDebug.h
// KVOWeakPropertyDebug
//
// Created by Vladimir Grichina on 12.01.13.
// Copyright (c) 2013 Vladimir Grichina. All rights reserved.
//
#import <Foundation/Foundation.h>
@vgrichina
vgrichina / booking.ts
Last active November 28, 2018 23:40
Booking train and hotel
book_train_and_hotel() : void { // Needs 6 MANA.
// 3 for train and callback and 3 for hotel and callback.
// E.g. book_train and book_hotel doesn't need additional mana, so only 1 MANA for a call.
// Callback may need 1 additional to cancel train or hotel booking if one of them failed.
assert_has_mana(6);
let hotelBooking = bookHotel.withMana(3).withCoins(1000).book(sender());
let trainBooking = bookTrain.withMana(3).withCoins(1000).book(sender());
@vgrichina
vgrichina / CellBackgroundView.h
Created November 12, 2012 21:39
Customizable background view for UITableViewCell in grouped table view
//
// CellBackgroundView.h
//
//
#import <UIKit/UIKit.h>
typedef enum {
CellPositionTop,
CellPositionMiddle,
@vgrichina
vgrichina / callback.js
Last active July 12, 2019 00:31
Spin up temporary webserver to handle callback from browser
const http = require('http');
const url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
try {
@vgrichina
vgrichina / load-test.js
Last active September 13, 2019 23:12
load testing nearcore payments
const nearlib = require('nearlib');
const { signTransaction, transfer } = nearlib.transactions;
const { base_decode } = nearlib.utils.serialize;
const sleep = (ms) => new Promise((resolved) => setTimeout(resolved, ms));
(async () => {
const [,, accountId, txCount] = process.argv;
const near = await nearlib.connect({...require('near-shell/get-config')(), deps: { keyStore: new nearlib.keyStores.UnencryptedFileSystemKeyStore('./neardev') } });
@vgrichina
vgrichina / array.c
Created July 24, 2010 21:45 — forked from tj/array.c
//
// array.h - CKit
//
// (c) 2009 TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
//
#ifndef __CKIT_ARRAY__
#define __CKIT_ARRAY__
[I] ➜ yarn start
yarn run v1.21.1
warning package.json: No license field
$ npm run build && near deploy --wasmFile ./contract/res/status_message.wasm
npm WARN lifecycle The node binary used for scripts is /var/folders/3c/zjk2krns25s75x_z2_wdvgg80000gn/T/yarn--1580160108615-0.8711654915114355/node but npm is using /Users/vg/n/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
> blank-rust-proj-vg@0.0.1 build /Users/vg/Documents/create-near-app/blank-rust-proj-vg
> cd contract && ./build.sh
Updating crates.io index
async function deploy(options) {
const configPath = process.cwd() + '/src/config';
const config = require(configPath)(process.env.NODE_ENV || 'development');
const near = await nearlib.connect({...config, deps: { keyStore: new UnencryptedFileSystemKeyStore('./neardev') } });
const contractData = [...fs.readFileSync(options.wasmFile)];
const account = await near.account(options.accountId);
await account.signAndSendTransaction(options.accountId, [
deployContract(contractData),
// TODO: Use whatever actual params need to be for functionCall or include any other actions as well