Skip to content

Instantly share code, notes, and snippets.

@pgbytes
pgbytes / SimpleImageConverter.java
Created August 1, 2014 07:30
Convert java.awt.Image to byte array #java #images
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
public class SimpleConvertImage {
@pgbytes
pgbytes / scp_commands.sh
Created August 1, 2014 13:03
SCP Commands #linux_commands
Copy Jars to remote locations
#!/bin/bash
nodes="192.168.2.70 192.168.2.71 192.168.2.72 192.168.2.73 192.168.2.74 192.168.2.75"
for node in $nodes
do
echo deploy node: $node
ssh -o StrictHostKeyChecking=no user@$node 'mkdir /home/user/vrnet &'
@pgbytes
pgbytes / downloadFileIOUtils.java
Created August 7, 2014 14:31
Download a web resource using apache commons #java
private byte[] downloadObject(String srcUrl) throws IOException
{
URL url = new URL(srcUrl);
InputStream in = new BufferedInputStream(url.openStream());
return IOUtils.toByteArray(in);
}
@pgbytes
pgbytes / displayMatchingArrayElements.js
Last active August 29, 2015 14:05
Display documents with array elements - matching the given condition in the array elements - gives back only the matching array elements
db.gSearchParseResultBundle.find({"units.displayedUrl":"www.toptarif.de/gasvergleich"},{_id:0, units:{$elemMatch:{"displayedUrl" : "www.toptarif.de/gasvergleich"}}});
@pgbytes
pgbytes / promises.js
Created August 10, 2016 21:03
Concept of nested promises
function getLocation() {
return new Promise(function (resolve, reject) {
resolve('Lucknow');
});
}
function getWeather(location) {
return new Promise(function (resolve, reject) {
resolve('It\'s 39 degrees in ' + location);
});
@pgbytes
pgbytes / pom.go
Created April 11, 2018 13:35
Generate an xml file, write to file and load it from file.
package models
import (
"encoding/xml"
"errors"
"io/ioutil"
"os"
"gopkg.in/resty.v1"
"crypto/tls"
"encoding/json"
@pgbytes
pgbytes / JavaMapAdapter.java
Created September 18, 2018 13:00
Parsing Map<K,V> to and from JSON
import _.model.MapEntry;
import _.model.MapType;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.HashMap;
import java.util.Map;
public class JavaMapAdapter<K,V> extends XmlAdapter<MapType<K,V>, Map<K, V>> {
@pgbytes
pgbytes / bash-executor.go
Created February 15, 2019 16:20
bash-executor using github.com/go-cmd
package services
import (
"fmt"
"github.com/go-cmd/cmd"
"github.com/golang/glog"
"time"
)
type BashExecutor struct {
@pgbytes
pgbytes / benchmark_results.sh
Last active June 11, 2019 06:10
concurrent merge sort
goos: darwin
goarch: amd64
pkg: puzzles-golang/algos/mergesort
BenchmarkConcurrentMergeSort_20-12 100000 15146 ns/op
BenchmarkConcurrentMergeSort_50-12 50000 32069 ns/op
BenchmarkConcurrentMergeSort_80-12 30000 49633 ns/op
BenchmarkConcurrentMergeSort_200-12 10000 104311 ns/op
BenchmarkConcurrentMergeSort_500-12 10000 221560 ns/op
BenchmarkConcurrentMergeSort_5000-12 500 2779299 ns/op
BenchmarkConcurrentMergeSort_100000-12 20 57669829 ns/op
{
"settingsReloadIntervalMinutes": 1,
"fullscreen": false,
"autoStart": false,
"lazyLoadTabs": true,
"websites": [
{
"monolith": "true",
"url": "https://app.google.stackdriver.com/dashboards/1197036787694873609?project=prod-co",
"duration": 20,