Skip to content

Instantly share code, notes, and snippets.

View derencius's full-sized avatar
🍀
Wish me luck, I'm fixing my bugs

Marcus Derencius derencius

🍀
Wish me luck, I'm fixing my bugs
View GitHub Profile
# add this file as config/initializers/will_paginate_postgresql_count.rb
# in a Rails application
module WillPaginate
module Finder
module ClassMethods
# add '1=1' to paginate conditions as marker such that the select from the pg_class
# is used to approximate simple rows count, e.g.
# Foo.paginate(:page => params[:page], :conditions => "1=1")
Remote.WithJsValidation = $.klass(Remote.Base, {
initialize: function() {
$(this.element).validate();
},
onsubmit: function(event) {
if ($(this.element).valid()) {
return true;
} else {
event.preventDefault();
return false;
@derencius
derencius / flatten.pc
Created July 30, 2010 14:51
CSV export from Oracle. Flatten.c was found on AskTom forum.
/* Compile Me With
gcc -O3 flatten.c -o flatten -L/oracle/rdbms/9.2.0/orax011/lib32 -lclntsh -lclntst9
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_VNAME_LEN 30
#define MAX_INAME_LEN 30
var to;
$(function() {
// initialize timer to update div every 5 seconds
to = setTimeout(message_load(), 5000);
});
function message_load() {
$.get("/messages",function(data) {
if (data.VERIFICA_SE_TEM_CONTEUDO) {
alert(data.conteudo);
# is it risky to trust on updated_at ?
# Summary: all products with no price on API should be disabled.
start_time = Time.now
Product.transaction do
ProductApi.each do |e|
Product.find(e.code).update_attribute :price, e.price
end
start_date = Time.now
Variant.transaction do
100.times do
puts Variant.count :conditions => ['updated_at > ?', start_date]
sleep(1)
end
end
@derencius
derencius / utf8_header.rb
Created February 3, 2011 19:05 — forked from francesc/utf8encode.rake
thor file to add utf-8 header on ruby files. useful for converting ruby 1.8 projects to 1.9
class Utf8Header < Thor
desc "add", "Add Content UTF-8 on top of all .rb/.feature files"
# copy & pasted from https://gist.github.com/738245
def add
files = Array.new
["*.rb", "*.rake","*.feature"].each do |extension|
files.concat(Dir[ File.join(Dir.getwd.split(/\\/), "**", extension) ])
end
files.each do |file|
@derencius
derencius / xcode.rb
Created March 10, 2011 03:05
Download Xcode using wget. Useful for slow or intermittent connections. it uses wget and mechanize.
require 'rubygems'
require 'mechanize'
if ARGV.size < 3
puts %q{Usage: ruby xcode.rb USERNAME PASSWORD "DOWNLOAD_URL" [WGET_PARAMS]}
puts %q{Example: ruby xcode.rb myusername@apple.com 123456 "https://developer.apple.com/devcenter/download.action?path=/Developer_Tools/xcode_4_and_ios_sdk_4.3__final/xcode_4_and_ios_sdk_4.3__final.dmg" }
exit
end
a = Mechanize.new { |agent|
@derencius
derencius / client.rb
Created April 10, 2011 04:22
Using model's sequence next value before inserting for special manipulation.
# id : serial
# check_digit : integer
class Client
set_primary_key :id
before_create :define_check_digit
private
diff --git a/unactest1.c b/unactest1.c
index 519691d..00aafbf 100644
--- a/unactest1.c
+++ b/unactest1.c
@@ -26,415 +26,9 @@
#include "unac.h"
-static char* longstr_expected = "
+static char* longstr_expected = "";