Skip to content

Instantly share code, notes, and snippets.

View wolivera's full-sized avatar

Will wolivera

View GitHub Profile
@wolivera
wolivera / read_write_json_file.rake
Last active February 22, 2019 12:12
Task to read, write and save a JSON file in Ruby
namespace :json do
# Usage: rake json:set_fields[file_name]
desc "Set some sample fields to an existing JSON file"
task :set_fields, [:file_name] => :environment do |t, args|
file_name = args[:file_name]
file_folder = Rails.root.join('app','assets','sample') # Step over the right folder
file = File.read(file_folder.join(file_name + ".json")) # Get the JSON file
fields = JSON.parse(form) # Get the JSON data to parse
updated_fields = set_fields(fields) # Set required to ruby Hash
<!DOCTYPE HTML>
<html>
<head>
<!-- when using the mode "code", it's important to specify charset utf-8 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link href="jsoneditor/jsoneditor.css" rel="stylesheet" type="text/css">
<script src="jsoneditor/jsoneditor.min.js"></script>
</head>
{
"manifest_version": 2,
"name": "Instant JSON Editor",
"description": "Format, validate and edit JSON instantly",
"version": "1.0.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
var STORE_KEY = 'jsoneditor-text';
var editor = null;
function loadEditor() {
var container = document.getElementById('jsoneditor');
var options = { mode: 'code', onChange: onChange };
editor = new JSONEditor(container, options);
editor.setText(localStorage.getItem(STORE_KEY) || JSON.stringify({}));
}
@wolivera
wolivera / DocumentTracker.sol
Created November 30, 2018 19:21
Solidity contract to keep track of documents and its versions
pragma solidity ^0.4.24;
contract DocumentTrackContract {
struct Document {
DocumentVersion[] versions;
}
struct DocumentVersion {
bytes32 hash;
uint32 date;
@wolivera
wolivera / air-quality-current.json
Last active February 12, 2019 19:46
Breezometer API json samples
// Current Air Quality conditions using SF coordinates (37.7749° N, 122.4194° W) and full features
// https://api.breezometer.com/air-quality/v2/current-conditions?lat=37.7749&lon=-122.4194&key=API_KEY&features=breezometer_aqi,local_aqi,health_recommendations,sources_and_effects,pollutants_concentrations,pollutants_aqi_information
{
"metadata": null,
"data": {
"datetime": "2019-02-12T19:00:00Z",
"data_available": true,
"indexes": {
"baqi": {
@wolivera
wolivera / Jokes API Postman Collection.json
Created August 5, 2021 16:21
Jokes API Postman Collection
{
"info": {
"_postman_id": "267cb468-eb06-4021-9743-6ba3b0c2139d",
"name": "Jokes API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "GET Random Jokes",
"event": [
@wolivera
wolivera / Singleton.js
Last active June 23, 2022 11:33
GoF Singleton Pattern
class Database {
constructor(url) {
this.url = url;
}
static getInstance() {
if (typeof Database.instance === 'object') {
return Database.instance;
}
Database.instance = new Database('http//localhost:8545');
@wolivera
wolivera / Factory.js
Last active July 27, 2022 10:25
GoF Factory Pattern
// Products
// Abstract Product Class
class Vehicle {
getPrice() {
return `What type of vehicle do you want to get the price for?`;
}
}
@wolivera
wolivera / AbstractFactory.js
Created June 23, 2022 12:42
AbstractFactory
class Employee {
constructor(name) {
this.name = name;
}
say() {
console.log("I am employee " + this.name);
};
}