Skip to content

Instantly share code, notes, and snippets.

View krtschmr's full-sized avatar
🏠
Creating the future

Tim Kretschmer krtschmr

🏠
Creating the future
  • Amsterdam, Netherlands
  • 07:45 (UTC +02:00)
View GitHub Profile
class Testy
def easy
puts "hi"
end
def hash(a:, b:, c:)
puts a
puts b
@krtschmr
krtschmr / gist:06b84948783617cd345ed2c34ad5d8ee
Created October 9, 2019 11:09
circle-ci integration rails 6, mysql 5.7, influx, redis, rspec + code covereage
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
@krtschmr
krtschmr / gist:9e7b297763901efbe6cf02b4cb13ae5f
Last active September 14, 2023 06:33
qrcode with css helper
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 = RQRCode::QRCode.new(string, level: level).to_s.split("\n").collect(&:chars)
@qr_size = @qr_data.size
#!/usr/bin/python
import os
import sys
import time
import datetime
import commands
import json
gDebugMode = 1
gLogFile = "/home/ethos/gpu_hashrates.log"
@krtschmr
krtschmr / monero_wallet.rb
Created September 27, 2017 05:44
Monero::Wallet to access Monero-Wallet-RPC via ruby
# 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 self.new(amount); Money.new(amount, :xmr); end
def to_s; Money.new(amount, :xmr).format; end
end
class Monero::Wallet
@krtschmr
krtschmr / sonoff.rb
Created September 12, 2017 09:57
controll a sonoff-tasmota device via ruby
# Free to use. if you modify it, pls let me know, i might need your code aswell :-)
# github: krtschmr
# tim@krtschmr.de
# USAGE
# Straightforward
# Sonoff.on!("192.168.1.53")
# Sonoff.off!("192.168.1.53")
@krtschmr
krtschmr / rails_friendship_and_blocklist.rb
Last active September 12, 2023 14:19
a great way to implement friendship AND blocklists for a rails-application. including specs for minitest.
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
krtschmr / need_admin_approval.rb
Last active October 4, 2019 08:27
Extension for ActiveRecord to make any changes for an objects attributes protected and create a seperate ChangeRequest which needs to be approved
# usage
# your model
# need_admin_approval fields: [:name, :description], if: :published?, unless: :trusted_user?
module NeedAdminApproval
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
before_validation do
self.site_id = 1
self.username=Devise.friendly_token.first(4)
self.slug = Devise.friendly_token.first(4)
self.email = "#{Devise.friendly_token.first(4)}@ficken.de"
generated_password = Devise.friendly_token.first(8)
self.password = generated_password
self.password_confirmation = generated_password
end
@krtschmr
krtschmr / .rb
Created July 25, 2015 14:43
asd
require "titlefy/version"
module Titlefy
# call from your controller (mostly ApplicationController)
def titlefy
send :include, InstanceMethods
end
module InstanceMethods