Skip to content

Instantly share code, notes, and snippets.

<#if entries?has_content>
<#list entries as curEntry>
<#assign renderer = curEntry.getAssetRenderer() />
<#assign journalArticle = renderer.getArticle() />
<#assign AssetCategoryLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetCategoryLocalService") />
<#assign categories = AssetCategoryLocalService.getCategories("com.liferay.journal.model.JournalArticle", journalArticle.getResourcePrimKey()) />
<#if categories?has_content>
<#list categories as category>
${category.getName()}
@Dagnan
Dagnan / application.html.erb
Last active November 21, 2020 19:10 — forked from averyvery/application.rb
Inline CSS or JS in Rails 5
<!DOCTYPE html>
<html>
<head>
<%= inline_js 'application.js' %>
<%= inline_css 'application.css' %>
</head>
<body>
</body>
</html>
@carloscabo
carloscabo / js_module_closure.js
Last active March 17, 2016 15:34
JS Module with closure
;(function($, undefined) {
'use strict';
if (typeof window.MY_MODULE_NAME !== 'undefined') {
return;
}
//
// Module general vars
//
@rinze
rinze / build_dataset.py
Last active January 15, 2019 10:51
Parser para los archivos .DAT del Ministerio del Interior y el archivo de códigos de municipios del INE y código en R para gráficas simples.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
import codecs
import cStringIO
import os
from collections import namedtuple
def getParties(parties_file):
@averyvery
averyvery / application.rb
Last active May 27, 2024 07:35
Inline CSS or JS in Rails
config.assets.precompile += [
# precompile any CSS or JS file that doesn't start with _
/(^inline[^_\/]|\/[^_])[^\/]*.(js|css)$/,
...
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {
@rsierra
rsierra / 1ST README.md
Last active December 13, 2015 16:49
Rails <= 2.3 patch for CVE-2013-0269, CVE-2013-0276 and CVE-2013-0277 vulnerabilities

Rails <= 2.3 patch for CVE-2013-0269, CVE-2013-0276 and CVE-2013-0277 vulnerabilities

Extracted from official patchs.

  • Add files in '/config/initializers' directory.

To test the JSON parser (CVE-2013-0269), try to parse a malicious json:

  • In console, before patch:
@dblock
dblock / api_logger.rb
Created December 10, 2012 01:43
API logger with Grape under Rails
class ApiLogger < Grape::Middleware::Base
def before
Rails.logger.info "[api] Requested: #{request_log_data.to_json}\n" +
"[api] #{response_log_data[:description]} #{response_log_data[:source_file]}:#{response_log_data[:source_line]}"
end
private
def request_log_data
@scottwb
scottwb / application_controller.rb
Created February 17, 2012 06:12
Get a list of all the filters on a given Rails 3 controller.
# Add these methods to your ApplicationController. Then, any controller
# that inherits from it will have these methods and can programmatically
# determine what filters it has set.
class ApplicationController < ActionController::Base
def self.filters(kind = nil)
all_filters = _process_action_callbacks
all_filters = all_filters.select{|f| f.kind == kind} if kind
all_filters.map(&:filter)
end
@tjh
tjh / character_set_and_collation.rb
Created January 31, 2012 16:07
Convert all Rails table column collation and character set
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''