Skip to content

Instantly share code, notes, and snippets.

View palmerabollo's full-sized avatar

Guido García palmerabollo

View GitHub Profile
@palmerabollo
palmerabollo / keystrokes.d
Created June 11, 2014 10:20
dtrace keystrokes
#!/usr/sbin/dtrace -s
syscall::read:entry
/execname == "sh" || execname == "ksh" || execname == "csh" ||
execname == "tcsh" || execname == "zsh" || execname == "bash"/
{
self->start = timestamp;
self->buf = arg1;
self->len = arg2;
}
# prerequisites: curl, jq (brew install jq), openssl
echo "To:"
read EMAIL
# retrieve user info (login+ssh key) from github
LOGIN=`curl -s https://api.github.com/search/users?q=$LOGIN | jq -r '.items[0].login'`
KEY=`curl -s https://api.github.com/users/$LOGIN/keys | jq -r '.[0].key'`
echo $KEY > $LOGIN.pub
@palmerabollo
palmerabollo / gist:f98483dd9aa3d4aebb4b
Created May 18, 2015 14:29
mongo logstash patterns
MONGO_LOG %{SYSLOGTIMESTAMP:timestamp} \[%{WORD:component}\] %{GREEDYDATA:message}
MONGO_QUERY \{ (?<={ ).*(?= } ntoreturn:) \}
MONGO_SLOWQUERY %{WORD} %{MONGO_WORDDASH:database}\.%{MONGO_WORDDASH:collection} %{WORD}: %{MONGO_QUERY:query} %{WORD}:%{NONNEGINT:ntoreturn} %{WORD}:%{NONNEGINT:ntoskip} %{WORD}:%{NONNEGINT:nscanned}.*nreturned:%{NONNEGINT:nreturned}..+ (?<duration>[0-9]+)ms
MONGO_WORDDASH \b[\w-]+\b
MONGO3_SEVERITY \w
MONGO3_COMPONENT %{WORD}|-
MONGO3_LOG %{TIMESTAMP_ISO8601:timestamp} %{MONGO3_SEVERITY:severity} %{MONGO3_COMPONENT:component}%{SPACE}(?:\[%{DATA:context}\])? %{GREEDYDATA:message}
@palmerabollo
palmerabollo / ip-save.js
Last active August 29, 2015 14:27
My first hook.io microservice
module['exports'] = function saveExternalIp (hook) {
var params = hook.params;
var store = hook.datastore;
var obj = { ip: params.ip, date: new Date() };
store.set('externalip', obj, function(err, result) {
if (err) {
return res.end(err.message);
}
// See http://hook.io/docs#data for more information
@palmerabollo
palmerabollo / ip-get.js
Last active August 29, 2015 14:27
My first hook.io microservice
module['exports'] = function getExternalIp(hook) {
var store = hook.datastore;
store.get('externalip', function(err, result) {
if (err) {
return res.end(err.message);
}
hook.res.write(JSON.stringify(result));
hook.res.end();
});
};
@palmerabollo
palmerabollo / tokbox.js
Last active December 2, 2015 09:34
Tokbox meet room for Slack
module['exports'] = function tokbox(hook) {
var request = require('request');
// The parameters passed in via the slash command POST request.
var params = hook.params;
console.log(JSON.stringify(params));
// Check that the hook has been triggered from our slash command by
// matching the token against the one in our environment variables.
if (params.token !== hook.env.tokbox_command_token) {
git pull --rebase origin master
git rebase -i origin/master
--
git commit --amend --no-ff
module['exports'] = function echoHttp (hook) {
console.log(hook.params);
console.log(hook.req.path);
console.log(hook.req.method);
console.log(hook.env);
hook.res.end(JSON.stringify(hook.params, true, 2));
};
import java.util.Map;
import org.elasticsearch.storm.EsBolt;
import backtype.storm.task.IOutputCollector;
import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.tuple.Tuple;
public class ExtendedESBolt extends EsBolt {
@palmerabollo
palmerabollo / gist:14244c813b67464e9b71
Created March 25, 2016 08:18
YuvImage in Android
public void uploadImage(byte[] data, int width, int height) {
final Context context = contextWeakReference.get();
YuvImage yuvimage = new YuvImage(data, ImageFormat.NV21, width, height, null);
try {
final File outputFile = FileUtils.createExternalFile(Environment.DIRECTORY_DCIM, ".jpeg");
final BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile));
yuvimage.compressToJpeg(new Rect(0, 0, width, height), 90, os); // compress level = 90