Skip to content

Instantly share code, notes, and snippets.

@vietlq
vietlq / curl.md
Created January 29, 2018 13:01 — forked from btoone/curl.md
A curl tutorial using GitHub's API

Introduction

An introduction to curl using GitHub's API.

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@vietlq
vietlq / pr.md
Created February 1, 2018 17:36 — forked from karlhorky/pr.md
Fetch all GitHub pull requests to local tracking branches
@vietlq
vietlq / howto_nat_traversal.md
Created February 5, 2018 11:39 — forked from mildred/howto_nat_traversal.md
How To TCP NAT Traversal using Node.js and a STUN Server

How To TCP NAT Traversal using Node.js and a STUN Server

With the scarecity of IPv4 addresses, and IPv6 still not available at large, NAT traversal is becoming a necessity. Especially with the generalisation of Carrier-grade NATs that you can find on mobile connections. Even with IPv6 you may suffer NAT66. Imagine your mobile device that gets only a single Ipv6 address, and you want to share it on your computer.

The solution might be in a decentralized protocol for address attribution such

@vietlq
vietlq / bitcoin-pay.rb
Created February 9, 2018 16:22 — forked from Sjors/bitcoin-pay.rb
This script demonstrates how a bitcoin transaction is created and signed. Just pass in your own address and private key and it will prepare a transaction for you. You can then copy & paste that transaction into a webservice like Blockchain to send it. I wrote this mostly to understand better how it works. I sometimes had to "cheat" and look at t…
#!/usr/bin/env ruby
require 'open-uri'
require 'JSON'
require 'digest/sha2'
require 'pry'
require 'bigdecimal'
require 'bitcoin' # Because I need to cheat every now and then
# Usage:
# gem install pry json ffi ruby-bitcoin
@vietlq
vietlq / call-then-sendtx-pattern.js
Created March 6, 2018 07:41 — forked from ethers/call-then-sendtx-pattern.js
call-then-sendtx pattern for Ethereum Dapps
/*
In Ethereum, a contract can be written so that it returns a value for eth_call.
A Dapp can then check for success or error value of eth_call, before calling eth_sendTransaction,
to take advantage of eth_call effectively being a "preview" of the code flow that the transaction
will take. In traditional client-server, clients can't ask servers beforehand what's going to
happen when the client makes a call; with Dapps contracts can be written so that clients can ask
for a "preview" of what is going to happen, before any funds/ethers are actually utilized
(eth_call does not cost any ethers).
Note: it is possible that in between eth_call and when eth_sendTransaction is actually mined,
@vietlq
vietlq / send_transfer_call.sol
Created March 9, 2018 10:56 — forked from tomw1808/send_transfer_call.sol
This is an example of the difference between "address.send()", "address.call.value()()" and "address.transfer()" in Solidity. If you like this example, then checkout my courses I do on Udemy (https://vomtom.at/tag/course/)
pragma solidity ^0.4.13;
contract someContract {
mapping(address => uint) balances;
function deposit() payable {
balances[msg.sender] += msg.value;
}
@vietlq
vietlq / index.js
Created March 20, 2018 08:46 — forked from AndrewJakubowicz/index.js
Example of using neon after `neon new ... ` step
// JS calling Rust
var addon = require('../native');
console.log(addon.hello());
// -> "hello node"
console.log(addon.adder(1,2));
// -> 3
console.log(addon.objAdder({a: 2, b: 5}));
@vietlq
vietlq / gist.md
Created March 29, 2018 12:20 — forked from rubensayshi/gist.md
Bitcoin Script Overview

rundown of different scripts and what is what and what goes where.

  • the prevoutScript is the script of the output being spend
  • the redeemScript is the script that is used to solve the P2SH
  • the signatureScript is the script that is taken into the signatureHash for signing
  • the witnessRedeemScript is the script that is used to solve the P2WSH
  • the scriptSig is what goes into the input.scriptSig when serializing the TX
  • the witnessScript is what goes into the input.witness when serializing the TX

for a P2KH

@vietlq
vietlq / DropZone.jsx
Created April 9, 2018 12:48 — forked from chrise86/DropZone.jsx
HTML5 Drag and Drop React Component
import React, {PropTypes} from 'react';
import classNames from 'classnames';
class BatchDropZone extends React.Component {
static propTypes = {
// function that recieves an array of files
receiveFiles: PropTypes.func.isRequired,