Skip to content

Instantly share code, notes, and snippets.

View bmvakili's full-sized avatar

Bijan Vakili bmvakili

View GitHub Profile
@bmvakili
bmvakili / dbupdate_after_service_builder
Created January 18, 2014 00:06
update iff tables already created with service builder, update id_ to id
SET FOREIGN_KEY_CHECKS = 0;
SET GROUP_CONCAT_MAX_LEN=32768;
SET @tables = NULL;
SELECT GROUP_CONCAT(table_name) INTO @tables
FROM information_schema.columns
WHERE table_schema = (SELECT DATABASE()) AND (LOWER(table_name) like 'x%' OR LOWER(table_name) like 'sm%' OR LOWER(table_name) like 'invites%' OR LOWER(table_name) like 'blockvendor%' ) AND column_name = 'id_';
select REPLACE(@tables, ',', ' change id_ id int(11) ; alter table ') into @tables;
select CONCAT('alter table ', @tables) into @tables;
SET FOREIGN_KEY_CHECKS = 0;
SET GROUP_CONCAT_MAX_LEN=32768;
SET @tables = NULL;
SELECT GROUP_CONCAT(table_name) INTO @tables
FROM information_schema.tables
WHERE table_schema = (SELECT DATABASE());
SELECT IFNULL(@tables,'dummy') INTO @tables;
SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
PREPARE stmt FROM @tables;
@bmvakili
bmvakili / Fancy Statistics 1
Created December 27, 2013 04:48
Liferay Marketplace - Portal Statistics - Template
<#assign liferay_ui = taglibLiferayHash["/WEB-INF/tld/liferay-ui.tld"] />
<table>
<thead>
<tr>
<th>
Name
</th>
<th>
Value
</th>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.airhacks</groupId>
<artifactId>javaee7-essentials-pom</artifactId>
<version>7.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>javax</groupId>
@bmvakili
bmvakili / find-lib-in-bin.sh
Created May 23, 2013 23:46
Show all libraries used by executables on linux To find the answer for all executables in the "/bin" directory:
#http://stackoverflow.com/questions/50159/show-all-libraries-used-by-executables-on-linux
find /bin -type f -perm /a+x -exec ldd {} \; \
| grep so \
| sed -e '/^[^\t]/ d' \
| sed -e 's/\t//' \
| sed -e 's/.*=..//' \
| sed -e 's/ (0.*)//' \
@bmvakili
bmvakili / gist:5295400
Created April 2, 2013 19:26
Liferay Groovy Script Get all roles; list User Groups associated with each role.
import com.liferay.portlet.usergroupsadmin.search.*;
import java.util.*;
import com.liferay.portal.service.*;
import com.liferay.portal.model.*;
import com.liferay.portal.model.UserGroup;
List<Role> roles = RoleLocalServiceUtil.getRoles(0,999999999);
for (Role role : roles) {
long roleId = role.getRoleId();
List<Group> roleGroups = GroupLocalServiceUtil.getRoleGroups(roleId);
for (Group roleGroup : roleGroups) {
@bmvakili
bmvakili / gist:4656884
Created January 28, 2013 16:18
Liferay Calendar - timezones, recurrence, and start/end times
ev0 = Packages.com.liferay.portlet.calendar.service.CalEventLocalServiceUtil.getEvent(66582);
recur0 = Packages.com.liferay.portlet.calendar.service.ICalUtil.toICalRecurrence(ev0.getRecurrenceObj())
dt0 = new Packages.net.fortuna.ical4j.model.Date(ev0.getStartDate());
sc0 = new Packages.net.fortuna.ical4j.model.Date(Packages.java.util.Calendar.getInstance().getTime());
no = recur0.getNextDate( dt0, sc0);
out.println("no: " + no);
///
out.println("-----")
tz = Packages.com.liferay.portal.kernel.util.TimeZoneUtil.getDefault();
ev = Packages.com.liferay.portlet.calendar.service.CalEventLocalServiceUtil.getEvent(66567);
@bmvakili
bmvakili / liferay-script-check-perms-3
Created November 2, 2012 17:23
Liferay scripts - check permissions on CalEvent
// ### Javascript Sample ###
companyId = 10153;
model = "com.liferay.portlet.calendar.model.CalEvent";
portletId = "8";
folder = Packages.com.liferay.portlet.calendar.service.CalEventLocalServiceUtil.getEvent(137535);
resource = Packages.com.liferay.portal.service.ResourceLocalServiceUtil.getResource(companyId, model, Packages.com.liferay.portal.model.ResourceConstants.SCOPE_INDIVIDUAL, folder.getPrimaryKey());
resourceActions = Packages.com.liferay.portal.security.permission.ResourceActionsUtil.getResourceActions(portletId, model);
administrator = Packages.com.liferay.portal.service.RoleLocalServiceUtil.getRole(folder.getCompanyId(), Packages.com.liferay.portal.model.RoleConstants.ADMINISTRATOR);
roleTypes = []
// ### Javascript Sample ###
folder = Packages.com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil.fetchDLFolder(14083);
resource = Packages.com.liferay.portal.service.ResourceLocalServiceUtil.getResource(folder.getCompanyId(), "com.liferay.portlet.documentlibrary.model.DLFolder", Packages.com.liferay.portal.model.ResourceConstants.SCOPE_INDIVIDUAL, folder.getPrimaryKey());
folderExpandoBridge = folder.getExpandoBridge().hasAttribute("hiddenFolderProperties");
resourceActions = Packages.com.liferay.portal.security.permission.ResourceActionsUtil.getResourceActions("20", "com.liferay.portlet.documentlibrary.model.DLFolder");
administrator = Packages.com.liferay.portal.service.RoleLocalServiceUtil.getRole(folder.getCompanyId(), Packages.com.liferay.portal.model.RoleConstants.ADMINISTRATOR);
roleTypes = []
@bmvakili
bmvakili / liferay-script-check-perms-2
Created October 10, 2012 20:54
Liferay scripts - check every page permission in default Group to see which roles have VIEW access
// Description: Liferay scripts - check every page permission in default Group to see which roles have VIEW access. It can also give the VIEW action permission to the Site Member role.
// Usage: Modify settings under "##CHANGE THESE##" section. Paste this script in the Control Panel->Server Administration->Script console and click "Execute"
//
// ## CHANGE THESE ##
var groupName = "Guest"; // this is the main group name
var showPublic = false; // set to true if public pages should be listed too. default behavior is that only private pages are considered when looking for VIEW action permission for Site Member role
var givePermission = false; // set to true to give VIEW action permission for Site Member role to all pages. Optionally apply this permission to a subset of pages by providing regular experssion to filter pages. See givePermissionRegex property below.
var givePermissionRegex = ".*"; // provide regular expression to filter Page Names
// ## No need to change below ##