Skip to content

Instantly share code, notes, and snippets.

View huhn511's full-sized avatar
🐔
🤖

huhn511

🐔
🤖
View GitHub Profile
@huhn511
huhn511 / _form.html.erb
Last active December 16, 2018 22:13
administrate trix editor field views app/views/fields/trix_field
<div class="field-unit__label">
<%= f.label field.attribute %>
</div>
<div class="field-unit__field">
<%= f.hidden_field field.attribute, id: field.attribute %>
<trix-editor input="<%= field.attribute %>"></trix-editor>
</div>
@huhn511
huhn511 / model.rb
Last active December 15, 2018 16:14
Custom validation method to validate correct image types
has_one_attached :image
validate :image_type
private
def image_type
if image.attached? == false
errors.add(:image, "is missing!")
end
@huhn511
huhn511 / storage.yml
Last active December 15, 2018 15:41
Declare a Google Cloud Storage service in config/storage.yml:
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
<div class="field">
<%= form.label :image %>
<%= form.file_field :image %>
</div>
@huhn511
huhn511 / create_active_storage_tables.active_storage.rb
Last active December 15, 2018 14:33
ActiveStorage Migration
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
def change
create_table :active_storage_blobs do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.bigint :byte_size, null: false
t.string :checksum, null: false
@huhn511
huhn511 / Local_PoW_Support.rb
Last active December 14, 2018 14:40
If you want to use this gem with public full node which does not support remote PoW on host, you can set local_pow to true when initialising the client.
require 'iota'
# With remote PoW
client = IOTA::Client.new(provider: 'https://node.iota-tangle.io:14265')
# If you use `client.api.attachToTangle` api here, you'll get error saying that attachToTangle command is not allowed
# With local pow
client = IOTA::Client.new(provider: 'https://node.iota-tangle.io:14265', local_pow: true)
# Now you can use `client.api.attachToTangle` api, which will do the proof-of-work on transaction and return the trytes that needs to be broadcasted
const converter = require('@iota/converter')
converter.trytesToAscii(transaction.signatureMessageFragment)
async function verifyData(data) {
// return false if the object has no signature
if (!data.sig) {
return false;
}
else {
// save the signature and delite it from the object
const signature = data.sig;
async function signData(data) {
// deletes old sig attribute, if existing
delete data.sig;
// convert obj to json
const json = JSON.stringify(data);
// load file with private key
const file = await util.promisify(fs.readFile)(path.join(privKeyFile));
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import SendButton from './components/SendButton'
import IOTA from 'iota.lib.js'
class App extends Component {
constructor(props) {