Skip to content

Instantly share code, notes, and snippets.

View boriscy's full-sized avatar
🏠
Working from home

Boris Barroso boriscy

🏠
Working from home
  • Lead With Purpose
  • Samaipata, Bolivia
View GitHub Profile
module Models::HstoreMap
def convert_hstore_to(to_type, *methods)
methods.each do |meth|
alias_method :"old_#{meth}", meth
define_method meth do
send(:"old_#{meth}").try(to_type)
end
end
end
parseDateDB = function(d) {
arr = d.split('-')
y = arr[0]
m = arr[1] * 1 - 1
d = arr[2]
try {
return new Date(y, m, d)
} catch (e)
return new Date()
}
@boriscy
boriscy / ssh_config
Created March 13, 2014 18:20
ssh configuration to make work on linuxmint 16 /etc/ssh/ssh_config
Host *
SendEnv LANG LC_*
HashKnownHosts yes
GSSAPIAuthentication yes
GSSAPIDelegateCredentials no
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
HostKeyAlgorithms ssh-rsa,ssh-dss
MACs hmac-md5,hmac-sha1,hmac-ripemd160
class Welss::Texas
BUILD = [:build_api, :build_county_name, :build_well_name]
def build
BUILD.each {|m| send(m) }
end
end

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert $1 -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 $2

Results

'use strict';
module.exports = function(grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// configurable paths
var paths = {
blue = '#16A9E3'
green = '#7FC06B'
width = 300
height = 150
space = 40
x = d3.scale.ordinal()
.rangeRoundBands([0, width], 10)
@boriscy
boriscy / authentication.rb
Created January 22, 2015 18:16
Models for polla
module Authentication
extend ActiveSupport::Concern
mattr_accessor :pepper, :stretches
attr_accessor :password, :password_confirmation
included do
validates_uniqueness_of :email, :if => "email.present?", :message => I18n.t("activerecord.errors.messages.existing_email"),
:allow_blank => true
class MigrateHstoreToJson < ActiveRecord::Migration
def up
rename_column :posts, :data, :data_hstore
add_column :posts, :data, :jsonb, default: {}, null: false, index: { using: 'gin' }
execute 'UPDATE "posts" SET "data" = json_object(hstore_to_matrix("data_hstore"))::jsonb'
remove_column :posts, :data_hstore
end
def down
rename_column :posts, :data, :data_jsonb
@boriscy
boriscy / convert_range.rb
Last active August 29, 2015 14:16
Convert ranges from old format to new
# convert from
# (0 - 21 - 71 - 121) : (0 - 0,491 - 0,563 - 0,66)
# to
# (0-20:0); (21-70:0.491); (71-120:0.563); (121:0.66)
require 'csv'
module ConvertRange
def self.convert(str)
ranges, values = str.split(":")
ranges.gsub!(/[^\d-]/, '')