Skip to content

Instantly share code, notes, and snippets.

@dncrht
dncrht / README.md
Last active April 19, 2019 04:43
SCRIPT-8
@dncrht
dncrht / client.rb
Created July 21, 2018 19:02
Upload file to Microsoft's OneDrive
# Usage:
# - Store refresh token on Redis under one_drive:refresh_token
# - Do OneDrive::Client.new.upload_file('/path/to/file')
module OneDrive
class Client
REFRESH_TOKEN = 'one_drive:refresh_token'.freeze
class NoTokens < StandardError; end
@dncrht
dncrht / bb.rb
Created January 8, 2017 10:30
Usborne's Bouncing Bug port to ncurses and Ruby
require 'ncurses'
class BouncingBug
FRAMES_PER_SECOND = 4
TIME_BETWEEN_FRAMES = 1.0 / FRAMES_PER_SECOND
attr_reader :scr
def initialize
*************************
IDENTIFICATION DIVISION.
*************************
PROGRAM-ID. PRV34915.
*****************************************************************
* *
* DEPARTAMENTO PRE-VALIDACION DE DECLARACIONES *
* DE DEL MODELO 349. EJERCICIO 2015 *
@dncrht
dncrht / tax_calc.rb
Last active February 5, 2022 15:53
Income tax calculator - Calculadora IRPF
class TaxCalc
TABLAS = {
retenciones_es: {
5550 => 0,
12450 => 19,
20200 => 24,
35200 => 30,
60000 => 37,
999999 => 45
},
@dncrht
dncrht / my_class_spec.rb
Created May 17, 2016 11:36
Using strip_heredoc outside Rails
require 'spec_helper'
require 'active_support/core_ext/string/strip'
class MyClass
def call
"this is\na pretty\n(¯`·._.·[ string ]·._.·´¯)\n"
end
end
describe MyClass do
@dncrht
dncrht / domain-suggestions.js
Created May 11, 2016 15:10
domainSuggestions is a jQuery plugin to show a list of domain suggestions for email fields
/**
*
* domainSuggestions shows a list of domain suggestions… for email.
*
* Inspired by autoEmail http://www.cxpartners.co.uk/cxblog/towards-an-easier-way-to-enter-email-addresses/
* which is based upon https://github.com/chrisyuska/auto-email
*/
(function($) {
@dncrht
dncrht / jquery.colorbox.js
Created April 8, 2016 13:16
HT's colorbox
/*!
Colorbox 1.6.1
license: MIT
http://www.jacklmoore.com/colorbox
HT modifications:
- simpler photo counter
- inlined svg controls
- prev, next, close positioned to the browser window
- close button is always visible
@dncrht
dncrht / fizzbuzz.rb
Created March 28, 2016 12:20
my fizzbuzz implementation
100.times do |i|
out = ''
out << 'fizz' if (i%3).zero?
out << 'buzz' if (i%5).zero?
out << i.to_s if out.empty?
puts out
end
@dncrht
dncrht / rxjs_bacon.md
Last active February 6, 2016 09:40
RxJS and Bacon.js equivalences

RxJS and Bacon.js equivalences:

Bacon.js RxJS
Create stream for keyup events from an element var inputText$ = $([data-js=my-input]).asEventStream('keyup').map('.target.value'); var inputText$ = Rx.Observable.fromEvent($('[data-js=my-input]'), 'keyup').pluck('target', 'value')
Create stream for keyup events from a live element var inputText$ = $(document).asEventStream('keyup', '[data-js=my-input]').map('.target.value'); var inputText$ = Rx.Observable.create(function(observer) {$(document).on('keyup', '[data-js=my-input]', function(e) {observer.onNext(e.target.value);});});
Subscribe to a stream inputText$.onValue(function(props) {…}); inputText$.subscribe(function(props) {…});
Create stream from promises Bacon.fromPromise($.get(url, {text: text})); Rx.Observable.fromPromise($.get(url, {text: text}));