Skip to content

Instantly share code, notes, and snippets.

View jensendarren's full-sized avatar

Darren Jensen jensendarren

View GitHub Profile
@jensendarren
jensendarren / fileutils_example.rb
Created January 8, 2015 12:46
An example of using FileUtils in Ruby
require 'fileutils'
# __FILE__ keyword in ruby
puts "The current ruby file being executed is #{__FILE__}"
# Gets the directory name of the file being executed
current_directory = File.dirname(__FILE__)
puts "The current directory is #{current_directory}"
# expands to reveal the pwd (Present working directory)
@jensendarren
jensendarren / contracts...Address Data Type...AddressType.sol
Created March 11, 2022 04:03
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract AddressType {
address public basicAddress = 0xeCc6425dB956125989C2c1a58A817bD90f86B3C0;
address public basicAddress2 = 0x9Fa413fad794c18fdd3A5Ead5734f042Eb920A20;
address payable anotherPayableAddress = payable(0x94fe479322fa107933d67b9e230a9B12B6c9a96d);
@jensendarren
jensendarren / contracts...Elementary Data Types...AddressType.sol
Created March 11, 2022 03:04
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract AddressType {
address public aDefaultAddress;
// Example of a non checksum address (not allowed by solidity compiler)
// Can fix using:
// web3.utils.toChecksumAddress('0xecc6425db956125989c2c1a58a817bd90f86b3c0')
@jensendarren
jensendarren / contracts...Elementary Data Types...IntegerType.sol
Created March 11, 2022 03:04
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract IntegerType {
// uint type is same as uint256
uint256 aUint;
// int type is same as int256
int256 anInt;
@jensendarren
jensendarren / contracts...Elementary Data Types...BoolType.sol
Created March 11, 2022 01:20
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract BoolType {
//a basic bool
bool public aBool;
function notBool() public view returns (bool) {
return !aBool;
@jensendarren
jensendarren / contracts...Elementary Data Types...BoolType.sol
Created March 11, 2022 01:07
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract BoolType {
bool public aBool;
function notBool() public view returns (bool) {
return !aBool;
}
@jensendarren
jensendarren / optparse_example.rb
Created January 8, 2015 12:48
An example of using OptionParser in Ruby
# Restrict arguments to a specified class.
require 'optparse'
class HelloParser
def self.parse(args)
options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: name"
opts.on('-n', '--name NAME', 'The name of the person to say hello to') do |name|
from decimal import *
#Sets decimal to 10000 digits of precision
getcontext().prec = 10000
def plouffBig(n): #http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula
pi = Decimal(0)
k = 0
while k < n:
pi += (Decimal(1)/(16**k))*((Decimal(4)/(8*k+1))-(Decimal(2)/(8*k+4))-(Decimal(1)/(8*k+5))-(Decimal(1)/(8*k+6)))
@jensendarren
jensendarren / listNumbersPossibleSum.js
Created July 13, 2020 10:13
Given a list of numbers an a number k, return whether any two number from the list add up to k
/*
Given a list of numbers an a number k, return whether any two number from the list add up to k
For example. given [10,15,3,7] and k of 17 return true sine 10 + 7 is 17.
Bonus can you do in a single pass?
*/
array = [7,15,3,7,8,3,4,100]
k = 23
@jensendarren
jensendarren / App.vue
Last active February 25, 2020 09:26
A VueJS Prototype for logging console output to the component
<!--Make sure to install @vue/cli-service-global first-->
<!--Serve this up using `vue serve` at the command line-->
<!--Details here: https://cli.vuejs.org/guide/prototyping.html -->
<template>
<div>
<h1>{{name}}</h1>
<b>Logging To Vue Component? <span>{{logging}}</span></b>
<br />
<button @click="testLog">Test Log</button>|<button @click="testWarn">Test Warn</button>|<button @click="toggleLogging">Toggle Logging</button>
<hr/>