This file contains 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
public int mySqrt(int x) { | |
if (x == 0 || x == 1) return x; | |
int start = 0, end = x; | |
while (end - start > 1) { | |
int mid = start + (end - start) / 2; | |
if (mid <= x / mid) { // Avoid int overflow | |
start = mid; | |
} else { | |
end = mid; |
This file contains 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
## Generate a keypair | |
openssl req -x509 -newkey rsa:2048 -sha256 -keyout example.key -out example.crt -subj "/CN=example.com" -days 3650 | |
## Create PFX keystore with this keypair | |
openssl pkcs12 -inkey example.key -in example.crt -export -out keystore.pkcs12 | |
## Convert PFX keystore into Java JKS keystore | |
keytool -importkeystore -srckeystore keys.pkcs12 -srcstoretype pkcs12 -destkeystore keystore.jks | |
## Other often used |
This file contains 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
openssl s_client -showcerts -connect www.domain.com:443 |
This file contains 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
// "p" is price/revenue array | |
// return the maximum revnue by cutting a rod with length "n" | |
cutrod (int[] p, n) { | |
if (n==0) return 0; | |
max=Integer.MIN_VALUE; | |
for (i = 1 to n) { |
This file contains 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
// Code detail -- https://blog.teamtreehouse.com/getting-started-speech-synthesis-api | |
// Demo -- https://codepen.io/matt-west/pen/wGzuJ | |
function sayit(text, voice) { | |
var msg = new SpeechSynthesisUtterance(); | |
msg.text = text; | |
msg.voice = voice | |
speechSynthesis.speak(msg); |
This file contains 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
javadoc ./com/sb/MyEnum.java -cp . -d testdir -author |
This file contains 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
ls *finanti*.sql | grep -E -v "^(1B|1C)" | xargs -I {} echo "-f {}" | xargs | |
// xargs supports parallel execution. |
This file contains 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
let rm = angular.element(document.body).injector().get("RM"); | |
rm.email = "my.email@hotmail.com" | |
angular.element(document.body).injector().get('MyDataService').getRmEmail(); |
This file contains 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
ssh -F ssh/config -N -L 1622:db-server-host:1622 jump-host-ssh-alias | |
sqlplus "user/pwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1622))(CONNECT_DATA=(SERVICE_NAME=THE_DB_SCHEMA)))" |
This file contains 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
const usage = () => console.log(` | |
Usage: | |
node decoder.js <file-path> | |
The script will decode any base64-encoded value for each line, | |
and create x.decoded.xml under the same folder. | |
`); | |
if (process.argv.length < 3) { | |
usage(); | |
process.exit(0); |
OlderNewer