Skip to content

Instantly share code, notes, and snippets.

@czhc
czhc / call.rb
Last active August 21, 2023 07:36
Ruby class implied method call?
class Greeter
def hello(name)
puts "Hello #{name}!"
end
def call(name)
puts "Calling #{name}!"
end
end
@czhc
czhc / testing_remote_contracts_w_ethersjs.md
Last active July 19, 2021 16:02
Testing remote contracts using ethers.js
@czhc
czhc / contract_ethers.js
Last active June 29, 2021 09:05
Interacting with contracts with web3.js and ethers.js
const ethers = require('ethers');
const provider = new ethers.providers.JsonRpcProvider('http://localhost:7545'); //using Ganache
const network = provider.getNetwork();
const signer = provider.getSigner();
const artifact = require('./client/src/contracts/Item.json');
const contractAddress = '0xE0dc8879F4CF0c2273DF277A570F3884B98A692C';
const contract = new ethers.Contract(contractAddress, artifact.abi, signer);
let paidWei = (await contract.paidWei()).toString()
@czhc
czhc / dr.py
Last active July 20, 2020 08:46
dr.py deepracer
'''
"all_wheels_on_track": Boolean, # flag to indicate if the agent is on the track
"x": float, # agent's x-coordinate in meters
"y": float, # agent's y-coordinate in meters
"closest_objects": [int, int], # zero-based indices of the two closest objects to the agent's current position of (x, y).
"closest_waypoints": [int, int], # indices of the two nearest waypoints.
"distance_from_center": float, # distance in meters from the track center
"crashed": Boolean, # Boolean flag to indicate whether the agent has crashed.
"is_left_of_center": Boolean, # Flag to indicate if the agent is on the left side to the track center or not.
"offtrack": Boolean, # Boolean flag to indicate whether the agent has gone off track.
@czhc
czhc / data.sql
Last active March 12, 2020 06:50
data.sql
CREATE TABLE IF NOT EXISTS `books` (
`id` int(6) unsigned NOT NULL,
`title` varchar(200) NOT NULL,
`published_at` datetime(6) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
INSERT INTO `books` (`id`, `title`, `published_at`) VALUES
('100', 'The earth is flat', '2012-01-05 15:05:23'),
('200', 'One hundred angels can dance on the head of a pin', '2013-11-08 15:05:23'),
@czhc
czhc / exactly_once_processing.md
Created April 24, 2019 01:32
Understanding Exactly-Once Processing in Messaging Systems, 2019
@czhc
czhc / install.sh
Created January 10, 2019 05:48
Installing IM from source
#!/bin/sh
mkdir ~src/
cd ~src
wget http://www.imagemagick.org/download/ImageMagick-6.9.10-23.tar.gz #or download latest tip ImageMagick.tar.gz
tar xf ImageMagick-6.9.10-23.tar.gz
cd ImageMagick-6.9.10-23/
./configure
make
make check
sudo checkinstall
@czhc
czhc / partitition_psql.sql
Last active November 15, 2018 03:19
partitioning with inheritance on plpgsql
create table events(id serial, name varchar, date timestamp);
do $$
begin
for r in 1..1000 loop
insert into events(name, date) values('event ' || r::varchar, now() - interval '4 months');
end loop;
for r in 1..1000 loop
insert into events(name, date) values('event ' || r::varchar, now() - interval '3 months');
@czhc
czhc / nginx.conf
Created June 7, 2017 09:18 — forked from conorh/nginx.conf
Using Nginx as a caching proxy for Refile with Ruby on Rails
http {
...
proxy_cache_path /data/perch.squaremill.com/shared/image_cache levels=1:2 keys_zone=images:10m;
...
}
@czhc
czhc / gist:b4e65d315fbe266664ff35c794933570
Created June 3, 2017 06:32 — forked from loisaidasam/gist:2774350
One liner for counting unique IP addresses from nginx logs
# One liner for counting unique IP addresses from nginx logs
# Feel free to comment with better ideas - I'm sure it's not the best way of doing this (I'm no awk ninja!)
#
# Sample output:
#
# $ cat example.com.access.log | awk -F " " '{a[$1]++ } END { for (b in a) { print b, "\t", a[b] } }'
# 66.65.145.220 49
# 92.63.28.68 126
cat example.com.access.log | awk -F " " '{a[$1]++ } END { for (b in a) { print b, "\t", a[b] } }'