Skip to content

Instantly share code, notes, and snippets.

# yield chunks (Array) of the full query to a block
# generates new Collections via self.model.all
# which has the advantage of dropping scope on
# hydrated objects
def block_batches(chunksize, &block)
new_options = self.query.options.dup
total = new_options[:limit] || self.count
new_options[:limit] = chunksize
new_options[:offset] = 0
@ack
ack / README.md
Created June 25, 2012 16:56
vcap hm leak

PATCH

cloud_controller/app/models/app.rb
   def set_defaults
-    self.metadata ||= {}
+    self.metadata = {} if new_record?
   end

VERSIONS:

  • ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
@ack
ack / rdbg
Created August 7, 2012 19:28
gdb-ruby
apt-get install -qqy gdb
cat > ~/.gdbinit <<EOF
define eval
call(rb_p(rb_eval_string_protect(\$arg0,(int*)0)))
end
define redirect_stdout
call rb_eval_string("\$_old_stdout, \$stdout = \$stdout, File.open('/tmp/ruby-debug.' + Process.pid.to_s, 'a'); \$stdout.sync = true")
==> actionmailer/CHANGELOG <==
## Rails 3.0.18
## Rails 3.0.17 (Aug 9, 2012)
* No changes.
## Rails 3.0.16 (Jul 26, 2012)
* No changes.
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <string.h>
#include <unistd.h>
void print_help(char *prog_name) {
printf("Usage: %s [-n] DEVNAME COMMAND\n", prog_name);
#!/usr/bin/env bash
#
# Functions
ok() {
echo -e '\e[32m'$1'\e[m';
}
die() {
echo -e '\e[1;31m'$1'\e[m'; exit 1;
@ack
ack / mesosphere-bootstrap.bash
Created November 6, 2015 04:02
super script to install mesosphere master or slave on ubuntu
#!/bin/bash
set -e
function init {
[[ ! -f /tmp/updated ]] && apt-get update -y && touch /tmp/updated
myip=$(ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')
}
#!/usr/bin/env python
"""
monitor a directory:
- id files via genpuid (musicdns)
- update ID3 tags and rewrite filename
REQUIREMENTS:
1) signup for an account and API key here:
https://secure.musicip.com/dns/index.jsp
#!/usr/bin/env python
import sys
import os
import pickle
import logging
import simplejson
import getopt
import inspect
import types
#!/usr/bin/env python
import os
import threading
import time
import socket
import SocketServer
import collections
import sys
import json