Skip to content

Instantly share code, notes, and snippets.

View DoguD's full-sized avatar
🎯
Focusing

Doğu Deniz Uğur DoguD

🎯
Focusing
View GitHub Profile
@DoguD
DoguD / RandomNumber.sol
Created April 25, 2022 21:29
A smart contract which generates a random number between 0 and desired maximum.
// SPDX-License-Identifier: MIT
/**
A simple Solidity smart contract which generates a random number between 0 and the desired max number.
Uses two functions to generate the random number:
- First "prepareRandom" should be called. The function will set the "preparationBlockNumber" to the current block number.
- Second "roll" should be called to generate the number. The function generates a random number using current block difficulty, timestamp, caller address,
and the blockhash of the block when "prepareRandom" has been called. This way, as the blockhash of the block can't be know before the "prepareRandom" transaction goes thorugh,
the result of the roll can't be predicted and thus manipulated.
How many times the roll has been called and all the previous results are recorded in the blockchain.
"""
Author: Dogu Deniz UGUR (Github: DoguD), 2020
The methodology behind the code has been tried to explained via comments.
All assumptions and notes are also mentioned as comments when necessary.
"""
def get_result(src_list, target, result_list):
"""Note: Although I couldn't find a counter example myself this algorithm may not always return the result with shortest
number of elements."""
@DoguD
DoguD / app.py
Created June 6, 2020 20:04
Chalice code for getting presigned S3 URL>
from chalice import Chalice
import boto3
import json
app = Chalice(app_name='s3_presigned_file_upload')
BUCKET_NAME = '<INSERT_BUCKET_NAME_HERE>'
REGION = '<INSERT_REGION_HERE>'
@DoguD
DoguD / CORS Configuration
Created June 6, 2020 20:01
CORS Configuration for S3 Presigned URL file upload
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
@DoguD
DoguD / app.py
Created June 6, 2020 17:43
Chalice initial app.py
from chalice import Chalice
app = Chalice(app_name='s3_presigned_file_upload')
@app.route('/')
def index():
return {'hello': 'world'}
@DoguD
DoguD / rdsconfig.py
Created May 27, 2020 20:09
RDS config format for ENGG4930C-ForeSee-api.
db_username = <YOUR_DB_USERNAME>
db_password = <YOUR_DB_PASSWORD>
db_name = <YOUR_DB_NAME>
db_endpoint = <YOUR_DB_ENDPOUNT>
default_platform(:android)
platform :android do
desc "Do UI Tests on CircleCI"
lane :ui_test do
# Run all Tests
sh('cd .. && ./gradlew app:connectedAndroidTest')
# Run spesific Tests
# sh('cd .. && ./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.package=<INSERT_YOUR_TEST_PACKAGE_HERE(com.app.myapp.emulatortests)>')
end
- run: avdmanager create avd -n Nexus_5X_API_26_x86 -k "system-images;android-26;default;x86" -d "Nexus 5X"
- run: osascript ./fastlane/recording_related/dismiss_warning.scpt # Dismisses the same named computer error
- run:
name: Run emulator in background
command: /usr/local/share/android-sdk/tools/emulator @Nexus_5X_API_26_x86 -skin 1080x2066 -memory 2048 -noaudio
background: true
- run:
name: Run Tests
command: bundle exec fastlane ui_test
no_output_timeout: 30m
- *restore_gradle_cache
- *android_dependencies
- *save_gradle_cache
- *restore_gems_cache
- *ruby_dependencies
- *save_gems_cache
run:
name: Install emulator
command: (yes | sdkmanager "platform-tools" "platforms;android-26" "extras;intel;Hardware_Accelerated_Execution_Manager" "build-tools;26.0.0" "system-images;android-26;default;x86" "emulator" --verbose) || true