Skip to content

Instantly share code, notes, and snippets.

@OhJia
OhJia / backup-github.sh
Created June 27, 2018 05:10 — forked from rodw/backup-github.sh
A simple script to backup an organization's GitHub repositories, wikis and issues.
#!/bin/bash
# A simple script to backup an organization's GitHub repositories.
# NOTE: if you have more than 100 repositories, you'll need to step thru the list of repos
# returned by GitHub one page at a time, as described at https://gist.github.com/darktim/5582423
GHBU_BACKUP_DIR=${GHBU_BACKUP_DIR-"github-backups"} # where to place the backup files
GHBU_ORG=${GHBU_ORG-"<CHANGE-ME>"} # the GitHub organization whose repos will be backed up
# (if you're backing up a user's repos instead, this should be your GitHub username)
GHBU_UNAME=${GHBU_UNAME-"<CHANGE-ME>"} # the username of a GitHub account (to use with the GitHub API)
043bdcf0f7dab0418c87e2adaafc886f450b6f23e7c0a8a443cd29d619b3bd2237110135f356d000815b0e96a773e66d7d31b3725a60b856298d42f0bb670e0627;gleuch
@OhJia
OhJia / app.js
Created December 11, 2017 23:53
RedEnvelope.deployed().then((i) => {
return i.claim(App.getPasscode(), claimIndex, { from: web3.eth.accounts[0] })
}).then((result) => {
// Look for Claimed event in logs
for (var i = 0; i < result.logs.length; i++) {
var log = result.logs[i];
if (log.event === 'Claimed') {
console.log('Claimed event found! ', parseInt(log.args._id), parseInt(log.args._value));
renderClaimedEnvelope(parseInt(log.args._id));
function checkPasscode(string _passcode, uint _envelopeIndex) public returns (bool) {
address creator = textToAddress[_passcode];
bytes32 submittedHash = sha3(creator, _passcode);
Envelope storage env = envelopes[_envelopeIndex];
return submittedHash == env.hash;
}
event Claimed(
address indexed _from,
uint _id,
uint _value
);
function claim(string _passcode, uint _envelopeIndex) public {
Envelope storage env = envelopes[_envelopeIndex];
require (checkPasscode(_passcode, _envelopeIndex));
window.addEventListener('load', () => {
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
console.warn(`Using web3 detected from external source. If you find that your accounts don't appear or you have 0 MetaCoin, ensure you've configured that source properly. If using MetaMask, see the following link. Feel free to delete this warning. :) http://truffleframework.com/tutorials/truffle-and-metamask`);
// Use Mist/MetaMask's provider
window.web3 = new Web3(web3.currentProvider);
} else {
console.warn(`No web3 detected. Falling back to http://localhost:8545. You should remove this fallback when you deploy live, as it's inherently insecure. Consider switching to Metamask for development. More info here: http://truffleframework.com/tutorials/truffle-and-metamask`);
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
window.web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545
import { default as Web3 } from 'web3';
import { default as contract } from 'truffle-contract';
// Import contract artifacts and turn them into usable abstractions.
import redenvelopeArtifacts from '../../build/contracts/RedEnvelope.json';
var RedEnvelope = contract(redenvelopeArtifacts);
window.App = {
start: () => {
window.addEventListener('load', () => {
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
console.warn(`Using web3 detected from external source. If you find that your accounts don't appear or you have 0 MetaCoin, ensure you've configured that source properly. If using MetaMask, see the following link. Feel free to delete this warning. :) http://truffleframework.com/tutorials/truffle-and-metamask`);
// Use Mist/MetaMask's provider
window.web3 = new Web3(web3.currentProvider);
} else {
console.warn(`No web3 detected. Falling back to http://localhost:8545. You should remove this fallback when you deploy live, as it's inherently insecure. Consider switching to Metamask for development. More info here: http://truffleframework.com/tutorials/truffle-and-metamask`);
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
window.web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545
event Claimed(
address indexed _from,
uint _id,
uint _value
);
function claim(string _passcode, uint _envelopeIndex) public {
Envelope storage env = envelopes[_envelopeIndex];
require (checkPasscode(_passcode, _envelopeIndex));
function checkPasscode(string _passcode, uint _envelopeIndex) public returns (bool) {
address creator = textToAddress[_passcode];
bytes32 submittedHash = sha3(creator, _passcode);
Envelope storage env = envelopes[_envelopeIndex];
return submittedHash == env.hash; // This boolean will not return
}