This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Initialize console object used for logging in javascript code. | |
* For case when console object is not present (old browsers) use dump implementation. | |
*/ | |
window.console = window.console || {}; // in old browsers like IE7 there is no console object | |
console.info = console.info || function() {}; | |
console.error = console.error || function() {}; | |
console.warn = console.warn || function() {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map.metaClass.collectWithIndex = { yield -> | |
def collected = [] | |
delegate.eachWithIndex { key, value, index -> | |
collected << yield(key, value, index) | |
} | |
return collected | |
} | |
assert [a: 1, b: 1, c: 1].collectWithIndex { key, value, index -> key + value + index } == ["a10", "b11", "c12"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
Import Github issues from one repo to another. | |
The orignal work: https://github.com/mkorenkov/tools/blob/master/gh-issues-import/gh-issues-import.py | |
(assuming public domain license). | |
Used to migrate Github's Plone Conference 2012 temporary repository | |
to collective.developermanual issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Latency Comparison Numbers | |
-------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns | |
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms | |
Read 4K randomly from SSD* 150,000 ns 0.15 ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URL; | |
import java.security.SecureRandom; | |
import java.security.cert.CertificateException; | |
import java.security.cert.X509Certificate; | |
import javax.net.ssl.HostnameVerifier; | |
import javax.net.ssl.HttpsURLConnection; | |
import javax.net.ssl.KeyManager; | |
import javax.net.ssl.SSLContext; | |
import javax.net.ssl.SSLSession; | |
import javax.net.ssl.TrustManager; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.*; | |
import java.io.*; | |
/* PROXY SETTINGS */ | |
System.getProperties().put("proxySet", "true"); | |
System.getProperties().put("proxyHost", "some.proxyserver.com"); | |
System.getProperties().put("proxyPort", "8080"); | |
Authenticator.setDefault(new MyAuthenticator()); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def c = new groovy.ui.Console(getClass().getClassLoader(), new Binding()) | |
c.setVariable("ctx",this) | |
c.run() | |
def done = false | |
c.frame.windowClosing = {done = true} | |
c.frame.windowClosed = {done = true} | |
while (!done) { | |
sleep(1000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using this runner every test report (gui, cli, html) will print names of tests not as test method | |
* names eg. "shouldBeLikeThatAndThat" but with spaces like "should be like that and that" for better | |
* readability. <br/><br/> | |
* | |
* <b>Usage</b>:<br/> | |
* | |
* <pre> | |
* <b>{@literal @}RunWith(ReadableTestNamesJUnitRunner.class)</b> | |
* public class DateParserTest { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); | |
//Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), false, "/page-name"); | |
HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request); | |
httpRequest = PortalUtil.getOriginalServletRequest(httpRequest); | |
//Retrieve layout id of another portlet. Layout is synonym for Page. Will it crash if there are multiple pages??? TODO test it | |
String portletId = "portletId"; // portlet id is string and you will find this in liferay database scheme or maybe it have some logic, but i don't know what and if it's compatible between liferay versions | |
long plid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), portletId); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new File(".").eachDirRecurse { dir -> | |
/* if you wonder why not to write ~/\\/ directly see | |
http://groovy.codehaus.org/Strings+and+GString#StringsandGString-SlashyStringliterals or | |
http://jira.codehaus.org/browse/GROOVY-2451 */ | |
def bs = "\\\\" | |
def fs = "/" | |
def pattern = ~/$bs|$fs/ |