Skip to content

Instantly share code, notes, and snippets.

Avatar

Dino Reić dux

  • JRNI
  • London, Zagreb, Munich
View GitHub Profile
@dux
dux / _
Last active May 3, 2021
Capistrano replacement via common rake tasks
View _
you will need
* hash_wia gem https://github.com/dux/hash_wia
* https://github.com/amazing-print/amazing_print
# to fully deploy application
rake remote:deploy
@dux
dux / paginate.rb
Last active Jan 28, 2021
Trivial and fast (does not execute count or any other unneeded requests) Ruby / Rails / Sinatra / Lux pagination
View paginate.rb
# @list = Paginate.set User, size: 40, name: :upage
# Paginate.render @list
# using: https://github.com/dux/html-tag/
module Paginate
extend self
def set rset, opts={}
opts[:size] ||= 20
opts[:name] ||= :page
@dux
dux / myapp.service
Created Jan 18, 2021
systemd sample script to start puma/rails app
View myapp.service
[Unit]
Description=Puma HTTP Server
After=network.target
[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple
# Preferably configure a non-privileged user
User=deploy
@dux
dux / asmodeus.rb
Created Jul 4, 2019
check if process pid is running and exit
View asmodeus.rb
class Asmodeus
attr_accessor :pid_file
def info text
puts 'Asmodeus: %s' % text
end
def pid_check no_check=false
return unless @pid_file
@dux
dux / _usage.js
Last active May 20, 2019
DOM create customElement or polyfil for older browsers. passes node + attributes
View _usage.js
// for svelte js, or any othe widget provider
let bindSvelteToDOM = function(name, klass) {
DOMCustomElement.define(name, function(node, opts) {
node.classList.add('mounted')
new klass({ target: node, props: opts })
})
}
import SvelteCheckbox from './svelte/checkbox.svelte'
bindSvelteToDOM('s-checkbox', SvelteCheckbox)
@dux
dux / rollup.config.js
Last active May 23, 2019
multi file rollup config with coffeescript, svelte, react and livereload
View rollup.config.js
import babel from 'rollup-plugin-babel'
import svelte from 'rollup-plugin-svelte'
import { scss } from '@kazzkiq/svelte-preprocess-scss';
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import coffee from 'rollup-plugin-coffee-script'
import livereload from 'rollup-plugin-livereload'
const production = !process.env.ROLLUP_WATCH;
@dux
dux / _threaded.rb
Last active Jul 31, 2021
Simple threaded/promisse-like runner for Ruby
View _threaded.rb
class Thread::Simple
attr_accessor :que, :size, :named
def initialize size: 5, sleep: 0.01
@sync = Mutex.new
@sleep = sleep
@size = size
@que = []
@threds = []
@named = {}
@dux
dux / demo.bash
Last active Nov 4, 2018
CLI demo builder, useful for asciinema.org - demo > https://asciinema.org/a/IanaNAq9CDKvUg7dweqxzhoAV
View demo.bash
# asciinema rec --overwrite tmp/demo.case
# bash demo.bash
type_and_run () {
printf '\033[01;37m@app $\033[0m '
for ((i=0; i<${#1}; i++)); do echo "after `jot -r 1 20 60`" | tclsh; printf "${1:$i:1}"; done;
echo;
$1;
echo;
}
View class_attributes.rb
# Defines class variable
def Object.class_attribute name, default=nil, &block
raise ArgumentError.new('name must be symbol') unless name.class == Symbol
ivar = "@cattr_#{name}"
instance_variable_set ivar, block || default
define_singleton_method(name) do |arg=:_undefined|
# define and set if argument given
@dux
dux / folder_model.rb
Last active Oct 28, 2018
Foder and Generic models
View folder_model.rb
# frozen_string_literal: true
class FolderModel
class << self
def find(key)
new(key)
end
def all