Skip to content

Instantly share code, notes, and snippets.

@jalex19100
jalex19100 / modifyVMAcl.ps1
Created September 26, 2015 02:02
Modify Azure VM ACL with Powershell
$name = "myVM"
$acl1 = New-AzureAclConfig
$vm = Get-AzureVM -ServiceName $name -Name $name
Set-AzureAclConfig -AddRule -ACL $acl1 -Order 100 -Action permit -RemoteSubnet "X.X.0.0/16" -Description "rule1"
Set-AzureAclConfig -AddRule -ACL $acl1 -Order 200 -Action permit -RemoteSubnet "X.X.0.0/16" -Description "rule2"
$vm | Get-AzureEndpoint | ForEach-Object {Set-AzureEndpoint -ACL $acl1 -Nam
e $_.Name -VM $vm}
@jalex19100
jalex19100 / PreferredBuilder.java
Last active November 10, 2015 14:13
My Preferred Builder Style - subtle and sweet. Unit testing friendly.
public class PreferredBuilder {
private String a;
private int i;
public PreferredBuilder() {
}
public PreferredBuilder(Builder builder) {
this.a = builder.a;
@jalex19100
jalex19100 / unpivot.sql
Created November 11, 2015 22:25
Oracle Unpivot with Tuple magic
-- Personal preference for unpivot
SELECT
SUBSTR(CLMN, 0, INSTR(CLMN,'_TOTAL_FROM', 1, 1)-1) AS COLOR, COUNT, COUNT/TOTAL*100 || '%' AS PCT, TOTAL, FROM_DATE, TO_DATE
FROM (
WITH SUMMARY AS
(SELECT
TO_DATE('2015-09-28','YYYY-MM-DD') AS FROM_DATE, TO_DATE('2015-10-01','YYYY-MM-DD') AS TO_DATE, 100000 AS TOTAL, 90000 AS BLUE,
5000 AS RED,3000 AS GREEN,0 AS YELLOW
FROM DUAL)
SELECT * FROM SUMMARY
Object.prototype.getName = function() {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((this).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
};
/**
* Remember to clear the previous refreshId before setting a new one. IE, in particular, will not remove the prior id automatically.
*/
var defaultRefreshInterval = 5; // minutes
var url = window.location.protocol + '//' + document.domain;
var refreshId;
var enableAutoRefresh = function() {
var interval = jQuery('#autorefresh_interval').val();
var enabled = jQuery('#enable_autorefresh').is(':checked');
@jalex19100
jalex19100 / LiferayScripting.rb
Last active November 11, 2015 22:44
Some handy ruby scripting for Liferay Administration
### LIST users
userCount = com.liferay.portal.service.UserLocalServiceUtil.getUsersCount();
users = com.liferay.portal.service.UserLocalServiceUtil.getUsers(0, userCount);
users.each{ |user| $out.print user.getFullName() + "\n"}
userCount = com.liferay.portal.service.UserLocalServiceUtil.getUsersCount();
users = com.liferay.portal.service.UserLocalServiceUtil.getUsers(0, userCount);
users.each{ |user| $out.print user.toString()+ "\n" }
### UPDATE user properties
@jalex19100
jalex19100 / simple.linux.commands.sh
Last active November 11, 2015 22:44
UNIX magic
# show any ghost/phantom resources that could still be affecting df but have been deleted
lsof +L 1 /home | grep -i deleted
# hog
du -sk *
# add up the hogs
du -sk * |sort -n| awk {'print $1'}| paste -sd+| bc
# use date to get the date 30 days ago
@jalex19100
jalex19100 / MavenWeblogicDeploy.cmd
Last active November 11, 2015 22:45
Maven Weblogic Deploy plugin
@REM store user credentials
@REM setDomainEnv.cmd only seems to work when you are in the same PWD
C:\Oracle\middleware\user_projects\domains\base_domain\bin>setDomainEnv.cmd
C:\Oracle\middleware\user_projects\domains\base_domain>java weblogic.WLST
wls:/offline> connect ('myUserid','myPassword','t3s://localhost:7001');
wls:/CLUSTERNAME/serverConfig> storeUserConfig(userConfigFile='wls.local.config', userKeyFile='wls.local.key');
@Deploying with maven weblogic plugin
mvn weblogic:wlst -nsu -Penv-local -DfileName=etc\redeploy.py -DfailOnError=false -Dargs="${wls.userConfigFile} ${wls.userKeyFile} ${wls.adminurl}"
@jalex19100
jalex19100 / GuavaOrdering.java
Last active November 11, 2015 22:45
Adhoc ordering outside of Comparable
Ordering<Item> o = new Ordering<Item>() {
@Override
public int compare(Item left, Item right) {
return Ints.compare(left.getValue(), right.getValue());
}
};
return o.max(listOfItem);
keytool -importkeystore -srckeystore "source-keystore.jks" -destkeystore "destination-keystore.jks" -srcstorepass password -deststorepass password -srcalias "alias"