Skip to content

Instantly share code, notes, and snippets.

Creating the future

Tim Kretschmer krtschmr

Creating the future
Block or report user

Report or block krtschmr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
krtschmr / gist:06b84948783617cd345ed2c34ad5d8ee
Created Oct 9, 2019
circle-ci integration rails 6, mysql 5.7, influx, redis, rspec + code covereage
View gist:06b84948783617cd345ed2c34ad5d8ee
version: 2 # use CircleCI 2.0
jobs: # a collection of steps
build: # runs not using Workflows must have a `build` job as entry point
parallelism: 1 # run three instances of this job in parallel
# branches:
# only:
# - master
docker: # run the steps with Docker
- image: circleci/ruby:2.6.3
environment: # environment variables for primary container
View gist:9e7b297763901efbe6cf02b4cb13ae5f
module QrCodeHelper
def qr_code(string, options={})
base_size = options.fetch(:width, 200)
@qr_logo = options.fetch(:logo, "qr_code_logo.png")
@qr_logo_size = options.fetch(:logo_size, 48)
level = options.fetch(:level, :l)
@qr_data =, level: level).to_s.split("\n").collect(&:chars)
@qr_size = @qr_data.size
import os
import sys
import time
import datetime
import commands
import json
gDebugMode = 1
gLogFile = "/home/ethos/gpu_hashrates.log"
krtschmr / monero_wallet.rb
Created Sep 27, 2017
Monero::Wallet to access Monero-Wallet-RPC via ruby
View monero_wallet.rb
# gem "money"
Money::Currency.register({ :priority => 1, :iso_code => "xmr", :iso_numeric => "846", :name => "Monero", :symbol => "XMR", :subunit => "", :subunit_to_unit => 1000000000000, :decimal_mark => ".", :thousands_separator => ""})
class XMR
def;, :xmr); end
def to_s;, :xmr).format; end
class Monero::Wallet
krtschmr / sonoff.rb
Created Sep 12, 2017
controll a sonoff-tasmota device via ruby
View sonoff.rb
# Free to use. if you modify it, pls let me know, i might need your code aswell :-)
# github: krtschmr
# Straightforward
# Sonoff.on!("")
krtschmr / rails_friendship_and_blocklist.rb
Last active Sep 17, 2019
a great way to implement friendship AND blocklists for a rails-application. including specs for minitest.
View rails_friendship_and_blocklist.rb
class User
has_many :relations, class_name: "User::Relation"
has_many :friends,-> { where user_relations: {type: :friendship, state: :confirmed }}, through: :relations
has_many :pending_friendships,-> { where user_relations: {type: :friendship, state: :pending }}, through: :relations, source: :friend
has_many :blocked_users,-> { where user_relations: {type: :block }}, through: :relations, source: :friend
def request_frienship(friend)
raise Relation::ForeverAlone if friend == self
raise Relation::AlreadyConfirmed if friend_with?(friend)
raise Relation::AlreadyRequestedFriendship if pending_friend_request?(friend)
krtschmr / need_admin_approval.rb
Last active Oct 4, 2019
Extension for ActiveRecord to make any changes for an objects attributes protected and create a seperate ChangeRequest which needs to be approved
View need_admin_approval.rb
# usage
# your model
# need_admin_approval fields: [:name, :description], if: :published?, unless: :trusted_user?
module NeedAdminApproval
def self.included(base)
module ClassMethods
View gist:8bdcb2a8f7c3d08ee7b7
before_validation do
self.site_id = 1
self.slug = Devise.friendly_token.first(4) = "#{Devise.friendly_token.first(4)}"
generated_password = Devise.friendly_token.first(8)
self.password = generated_password
self.password_confirmation = generated_password
View .rb
require "titlefy/version"
module Titlefy
# call from your controller (mostly ApplicationController)
def titlefy
send :include, InstanceMethods
module InstanceMethods
You can’t perform that action at this time.