Skip to content

Instantly share code, notes, and snippets.

@fforbeck
fforbeck / print_java_stacktrace
Created May 23, 2013 15:38
Print java stacktrace
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
sw.toString();
@fforbeck
fforbeck / mongo_ttl_indexes
Last active December 17, 2015 16:09
Activating MongoDB TTL for indexes
- Creating new index with ttl, the key must be date type and can not be a compound index.
> db.teste_ttl_idx.ensureIndex({ttl: 1}, {expireAfterSeconds: 5});
- Insert new documents
> db.teste_ttl_idx.insert({ttl: new Date()});
> db.teste_ttl_idx.insert({ttl: new Date()});
> db.teste_ttl_idx.insert({ttl: new Date()});
- You can do a find all to check if the elements were inserted and if they will be removed in the next 5 seconds after their creation.
@fforbeck
fforbeck / Setup Redis
Last active December 17, 2015 13:19
setup redis overcommit_memory
1 - Make sure to set the Linux kernel overcommit memory setting to 1. Add vm.overcommit_memory = 1 to /etc/sysctl.conf and then reboot or run the command sysctl vm.overcommit_memory=1 for this to take effect immediately.
2 - Make sure to setup some swap in your system (we suggest as much as swap as memory). If Linux does not have swap and your Redis instance accidentally consumes too much memory, either Redis will crash for out of memory or the Linux kernel OOM killer will kill the Redis process.
3 - Connector Configs
final int numClients = 150;
final JedisPoolConfig config = new JedisPoolConfig();
// Tests whether connection is dead when connection retrieval method is called
@fforbeck
fforbeck / jenkins-setup-ubuntu13.04
Last active December 17, 2015 10:18
Setup Jenkins Environment on Ubuntu 13.04
## Default setup: http://pkg.jenkins-ci.org/debian/
## Setup with oracle-jdk, mvn3, git, nginx and useful jenkins plugins
Remove OpenJDK first if installed by this command:
sudo apt-get purge openjdk*
Then add the Webupd8 Team PPA repository and then reload the packages:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
db.website_performance.aggregate(
[
{ $match : { 'domain' : { $in: ['xxx.com','porntube.com']} } },
{ $group: {
_id: '$domain',
sum_impressions: { $sum: "$impressions" },
sum_bids: { $sum: "$bids" },
sum_clicks: {$sum: "$clicks"},
sum_leads: {$sum: "$leads"},
sum_actual_cost: {$sum: "$actual_cost"},
db.website_performance.aggregate(
[
{
$match : { 'domain' : { $in: []} }
},
{
$group: {
_id: "$domain",
sum_impressions: { $sum: "$impressions" },
sum_bids: { $sum: "$bids" } }
SELECT cfr.DATE, cfr.USER_ID, cfr.CAMPAIGN_ID, SUM(cfr.SPENT_BUDGET) + IFNULL(cfpr.ACTUAL_COST,0) AS SPENT_BUDGET
FROM CONSOLIDATE_FINANCIAL_REPORT cfr
LEFT JOIN CONSOLIDATE_FINANCIAL_PARTNER_REPORT cfpr on cfpr.CAMPAIGN_ID = cfr.CAMPAIGN_ID and cfpr.DATE = cfr.DATE
WHERE cfr.DATE = '2013-03-26 00:00:00' AND cfr.USER_ID = 766
GROUP BY 1,2,3
ORDER BY 1,2,3;
public String normalize(String word) {
if (word == null || word.trim().isEmpty())
return word;
word = word.replaceAll("[ÂÀÁÄÃ]", "A");
word = word.replaceAll("[âãàáä]", "a");
word = word.replaceAll("[ÊÈÉË]", "E");
word = word.replaceAll("[êèéë]", "e");
word = word.replaceAll("ÎÍÌÏ", "I");
@fforbeck
fforbeck / a.js
Created March 18, 2013 22:08
aggregator
db.website_performance.aggregate(
[
{
$group: {
_id: "$domain",
sum_impressions: {
$sum: "$impressions"
},
sum_bids: {
$sum: "$bids"
var map_func = function() {
var imps = this.impressions;
var clicks = this.clicks;
emit(this.domain, {'impressions': imps, 'clicks': clicks });
};
var reduce_func = function(key, values) {