Skip to content

Instantly share code, notes, and snippets.

View rmaceissoft's full-sized avatar

Reiner Marquez rmaceissoft

View GitHub Profile
@rmaceissoft
rmaceissoft / rails_admin.rb
Created March 19, 2012 22:01
manual confirmation from admin (rails_admin) using custom action
# located at #{Rails.root}/config/initializers/rails_admin.rb
# RailsAdmin config file. Generated on March 01, 2012 17:53
# See github.com/sferik/rails_admin for more informations
RailsAdmin.config do |config|
config.current_user_method { current_user } # auto-generated
config.main_app_name = ['Timetracker', 'Admin']
config.authorize_with do
@rmaceissoft
rmaceissoft / gist:2129051
Created March 20, 2012 00:33
define fixed options for fields in a rails way
class Task < ActiveRecord::Base
# get an array with 0.0, 0.25, 0.50, 0.75, ...
@@hours_options = 0.step(3, 0.25).collect {|x| x}
belongs_to :proyect
# valudation rules
validates :hours, :inclusion => { :in => @@hours_options }
@rmaceissoft
rmaceissoft / testrunner.py
Last active October 2, 2015 10:37
customizing django testrunner
# Make our own testrunner that by default only tests our own apps
from django.conf import settings
from django.test.simple import DjangoTestSuiteRunner
class CustomTestRunner(DjangoTestSuiteRunner):
def build_suite(self, test_labels, *args, **kwargs):
return super(CustomTestRunner, self).build_suite(test_labels or settings.PROJECT_APPS, *args, **kwargs)
@rmaceissoft
rmaceissoft / error file
Created March 30, 2012 18:28
pdf generation
NoMethodError in Personal_invoices#show
Showing D:/PERFILES/Marquez/Jaratech/Workspace/branches/tt2-rails/app/views/personal_invoices/show.pdf.prawn where line #17 raised:
undefined method `headers=' for #<Prawn::Table:0x75612d8>
Extracted source (around line #17):
14: ["Email address", "#{@invoice.paypal_email}"]
15: ]
@rmaceissoft
rmaceissoft / gist:2855599
Created June 1, 2012 22:50
update_if_changed
def update_if_changed(model_instance, new_values):
has_changed = False
for field_name, field_value in new_values.items():
old_value = getattr(model_instance, field_name)
if old_value != field_value:
setattr(model_instance, field_name, field_value)
has_changed = True
if has_changed:
model_instance.save()
@rmaceissoft
rmaceissoft / queryset_iterator
Created July 3, 2012 18:35
django queryset iterator
"""
Taken from (http://djangosnippets.org/snippets/1949/)
and made some adjustments for cases when queryset is empty
"""
import gc
def queryset_iterator(queryset, chunksize=1000):
'''''
Iterate over a Django Queryset ordered by the primary key
@rmaceissoft
rmaceissoft / gist:3452971
Created August 24, 2012 17:08
generating unique id from datetime field in order to implement infinite scroll
import time
from django.db import models
class MyModel(models.Model):
# other fields...
start_date = models.DateTimeField()
unique_date = models.CharField(max_length=32, unique=True)
@rmaceissoft
rmaceissoft / fields.py
Created April 1, 2013 16:28
custom tastypie resource field to deserialize thumbnails generated with sorl-thumbnail
from tastypie.fields import DictField
from sorl.thumbnail import get_thumbnail
from sorl.thumbnail.helpers import ThumbnailError
class SorlThumbnailField(DictField):
"""
api field used to return a thumbnail generated with
sorl-thumbnail python library
/*global module:false*/
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
/* --------------------------------------- */
/* --( Variables )-- */
/* --------------------------------------- */
@rmaceissoft
rmaceissoft / gist:8109206
Created December 24, 2013 05:40
angularjs service to handle login/logout/status
define(function(require, exports, module) {
var angular = require('angular');
require('angular-cookies');
var usersModule = module.exports = angular.module('users', ['ngCookies'])
.factory('UserService', ['$http', '$cookieStore', function($http, $cookieStore) {
var currentUser = $cookieStore.get('user') || null;