Skip to content

Instantly share code, notes, and snippets.

class SegmentTree
class Segment
attr_reader :range, :value
def initialize range, value
raise ArgumentError, 'Range expected, %s given' % range.class.name unless range.is_a?(Range)
@range, @value = range, value
end
@samacs
samacs / IFormatter.php
Created October 22, 2012 16:23
A set of classes to demonstrate polymorphism.
<?php
/**
* Formatter interface.
*
* A contract to format.
*
* @category Formatter
* @package Formatter
* @author Saul Martinez <saul@sharkwebintelligence.com>
* @copyright 2012 Shark Web Intelligence
try {
$fecha = date('Y-m-d');
$mensajeId = mysql_insert_id();
$path = realpath($_SERVER['DOCUMENT_ROOT'] . DS . '..' . DS . 'adjuntos');
$path = $path . DS . implode(DS, explode('-', $fecha)) . DS . $mensajeId;
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
$file = $_FILES['archivo_adjunto'];

Having the following structure:

/app
|____/config/
     |____endpoints.json
     |____/endpoints/
          |
          |____/module1/
          |    |____contacts.json

| |____agendas.json

#
# voipmonitor.org configuration file
#
# location of this file is at ~/.voipmonitor.conf or /etc/voipmonitor.conf
# command line parameters overrides configuration directives in this file
# allowed comments are ; or #.
#
[general]
module CrudManagement
extend ActiveSupport::Concern
module ClassMethods
def crudify(resource_name, model_name = nil, options = {})
model_name ||= resource_name
options[:plural_name] ||= resource_name.to_s.pluralize
options[:singular_name] ||= resource_name.to_s.singularize
options[:permitted_params] ||= []
@samacs
samacs / Installation.md
Created June 22, 2017 13:57 — forked from albertbori/Installation.md
Automatically disable Wifi when an Ethernet connection (cable) is plugged in on a Mac

Overview

This is a bash script that will automatically turn your wifi off if you connect your computer to an ethernet connection and turn wifi back on when you unplug your ethernet cable/adapter. If you decide to turn wifi on for whatever reason, it will remember that choice. This was improvised from this mac hint to work with Yosemite, and without hard-coding the adapter names. It's supposed to support growl, but I didn't check that part. I did, however, add OSX notification center support. Feel free to fork and fix any issues you encounter.

Most the credit for these changes go to Dave Holland.

Requirements

  • Mac OSX 10+
  • Administrator privileges
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@samacs
samacs / searchable.rb
Last active August 17, 2017 13:51
A model concern to add search capabilities to a model.
module Searchable
extend ActiveSupport::Concern
included do
scope :filtered, lambda { |values|
current = all
filters.each do |key, method|
if values.try(:key?, key)
current = current.send(method, values[key]) if
curent.respond_to?(method)
#!/bin/bash
RUBY_VERSION=2.4.1
RAILS_VERSION=5.1.4
PB_VERSION=9.6
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
apt-add-repository multiverse