Skip to content

Instantly share code, notes, and snippets.

View vgrichina's full-sized avatar

Vladimir Grichina vgrichina

View GitHub Profile
@vgrichina
vgrichina / web4-min.zig
Last active March 15, 2024 00:20
Minimalistic Web4 demo using Zig language
const std = @import("std");
// NOTE: In smart contract context don't really have to free memory before execution ends
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
var allocator = arena.allocator();
// Import host functions provided by NEAR runtime.
// See https://github.com/near/near-sdk-rs/blob/78c16447486285fd952765ef3e727e16d6c8c867/near-sdk/src/environment/env.rs#L117
extern fn input(register_id: u64) void;
extern fn read_register(register_id: u64, ptr: u64) void;
@vgrichina
vgrichina / generated_bindings.ts
Last active October 16, 2023 13:24
Sample generated AssemblyScript BSON bindings
import "allocator/arena";
// TODO: Why cannot import from index?
// import { BSONEncoder, BSONDecoder } from "../../../assemblyscript-bson/assembly";
import { BSONEncoder } from "../../../assemblyscript-bson/assembly/encoder";
import { BSONDecoder } from "../../../assemblyscript-bson/assembly/decoder";
declare function sayHello(): void;
export class FooBar {
foo: i32 = 0;
select
format_timestamp('%m/%d/%Y %H:%M:%S', timestamp_millis(div(block_timestamp, 1000000))) as `Date`,
parse_bignumeric(json_value(args, '$.deposit')) / POW(cast(10 as bignumeric), 24) as `Sent Quantity`,
'NEAR' as `Sent Currency`
, receipt_predecessor_account_id
, receipt_receiver_account_id
from `bigquery-public-data.crypto_near_mainnet_us.receipt_actions`
where receipt_predecessor_account_id in
(
'vlad.near',
@vgrichina
vgrichina / parse-json.c
Last active December 5, 2022 06:49
chatGPT parse json lazy
// Tokenize the JSON string by splitting on `{`, `}`, `[`, and `]`, unless the character is inside a string
char* token = strtok(jsonCopy, "{}[],");
bool inString = false;
int depth = 0;
while (token != NULL) {
if (!inString && depth == 0 && strcmp(token, path) == 0) {
// The requested path was found, so return the next token as the value
token = strtok(NULL, "{}[],");
slice_t value = {
.len = strlen(token),
@vgrichina
vgrichina / gist:3968594
Created October 28, 2012 13:27
iPad mini simulation hack
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Some other stuff here ...
CGFloat scale = 4.71f/5.82f;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scale, scale);
self.window.transform = CGAffineTransformConcat(scaleTransform, self.window.transform);
self.window.clipsToBounds = YES;
[self statusBarChanged:nil];
select
to_timestamp(receipt_included_in_block_timestamp / 1000000000) as timestamp,
(args->>'deposit')::numeric / (10 ^ 24) as deposit,
receipt_predecessor_account_id
from action_receipt_actions
where receipt_receiver_account_id = 'root.near'
and receipt_predecessor_account_id != 'system'
@vgrichina
vgrichina / explorer-sqlite.js
Last active December 3, 2021 17:29
NEAR Explorer SQLite cheatsheet
sqlite3 = require('sqlite3')
db = new sqlite3.Database('db/testnet-database.sqlite')
db.all(`select name from sqlite_master where type='table'`, console.log)
db.all(`select * from transactions where actions like '%deploy%' limit 10`, console.log)
db.all(`select count(*) from transactions where actions like '%deploy%' limit 10`, console.log)
@vgrichina
vgrichina / PlistUtility.groovy
Created January 13, 2012 03:46
Simple OS X XML property list parser
import org.codehaus.groovy.grails.plugins.codecs.Base64Codec
class PlistUtility {
static parseXmlPlistText(String text) {
def xml = new XmlParser().parseText(text)
assert xml.name() == "plist"
def parseNode
parseNode = { node ->
@vgrichina
vgrichina / index.html
Last active April 5, 2021 00:20
libp2p pubsub web demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>js-libp2p parcel.js browser example</title>
</head>
<body>
@vgrichina
vgrichina / set-contract-to-deploy.md
Created June 18, 2020 22:28
How to deploy contract from AssemblyScript

You can do following to allow passing blob into contract without a lot of overhead:

export function setContractToDeploy(): void {
     env.input(0);
     util.read_register(0);
     // ...
}