Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Get current subscriber list
*/
function bl_get_subs() {
global $wpdb;
$table_name = $wpdb->prefix . "mailpoet_subscribers";
$retrieve_data = $wpdb->get_results("SELECT * FROM $table_name");
@robe5
robe5 / gist:1884495
Created February 22, 2012 11:56
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+X delete line
Ctrl+↩ insert line after
Ctrl+⇧+↩ insert line before
Ctrl+⇧+↑ move line (or selection) up
#Taken from http://coderrr.wordpress.com/2008/04/22/building-the-right-class-with-sti-in-rails/
class GenericClass < ActiveRecord::Base
class << self
def new_with_cast(*a, &b)
if (h = a.first).is_a? Hash and (type = h[:type] || h['type']) and (klass = type.constantize) != self
raise "wtF hax!!" unless klass < self # klass should be a descendant of us
return klass.new(*a, &b)
end
@robe5
robe5 / oshi.rb
Created July 8, 2010 08:58 — forked from anonymous/oshi.rb
require 'rubygems'
require 'eventmachine'
require 'em-websocket'
require 'json'
class Connection
attr_accessor :socket, :user_id
def initialize(socket, user_id)
@socket = socket
@robe5
robe5 / gist:375230
Created April 22, 2010 13:39 — forked from rails/gist:58761
var DateHelper = {
// Takes the format of "Jan 15, 2007 15:45:00 GMT" and converts it to a relative time
// Ruby strftime: %b %d, %Y %H:%M:%S GMT
time_ago_in_words_with_parsing: function(from) {
var date = new Date;
date.setTime(Date.parse(from));
return this.time_ago_in_words(date);
},
time_ago_in_words: function(from) {
# Rails 3 ajax calls
$(document.body).observe('click', function(event){
var element = event.findElement("a['data-remote']");
if (element) {
var method = element.readAttribute("data-method") || "get";
new Ajax.Request(element.readAttribute("href"), { method: method });
event.stop();
}
});
# Usado en rails (layout(layout, conditions={})) para pasar un hash a una variable y cada value como un array de strings:
conditions.each {|k, v| conditions[k] = Array(v).map {|a| a.to_s} }
#!/usr/bin/env ruby
command = '/opt/ruby-enterprise-1.8.6-20080810/bin/passenger-memory-stats'
memory_limit = 200 # megabytes
def running?(pid)
begin
return Process.getpgid(pid) != -1
rescue Errno::ESRCH
return false
Un Orden Topológico ordena los nodos de un grafo dirigido acíclico de forma que si hay una camino del nodo A al nodo B entonces A aparece antes que B en la ordenación.
<br /><br />
Ej:
<br />
<img alt="Grafo acíclico dirigido" title="Grafo acíclico dirigido" src="http://theproc.es/files/1376" />
<br />
El sentido de las flechas indica las dependencias. A depende de B y C, B depende de C, etc, etc.
<br /><br />
<img alt="Grafo ordenado topológicamente" title="Grafo ordenado topológicamente" src="http://theproc.es/files/1375" />
<br />
grafo = {"A" => ["B", "C"], "B" => ["C"], "C"=> [], "D" => ["B"], "E" => ["C"] }