Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
leandrosilva / mod_s3.psm1
Last active September 9, 2019 12:18
PowerShell module with helper functions to deal with AWS S3
####################
# EXTERNAL MODULES #
####################
# https://docs.aws.amazon.com/powershell/latest/reference/Index.html
if (-not (Get-Module -ListAvailable -Name AWSPowerShell)) {
"AWS module is not installed. Let's get it installed..."
Install-Module -Name AWSPowerShell
}
@leandrosilva
leandrosilva / mod_eslog.psm1
Last active September 4, 2019 21:09
PowerShell module to send log to ElasticSearch
###############################
# YOUR LOGS TO ELASTIC SEARCH #
###############################
function Get-ESConfig () {
[xml] $log4netConfig = Get-Content -Path $env:CONFIG_LOGGER_FILE
return $log4netConfig.log4net.appender | Where-Object { $_.name -eq "ElasticSearchAppender" }
}
@leandrosilva
leandrosilva / gcd.js
Last active October 13, 2018 18:11
Imperative style solution of the GCD problem
function gcd(numbers) {
let results = {};
for (let i = 0; i < numbers.length; i++) {
let divisor = numbers[i];
for (let j = 0; j < numbers.length; j++) {
let number = numbers[j];
if (number == divisor) continue;
let result = number % divisor;
@leandrosilva
leandrosilva / kmers.js
Last active October 12, 2018 04:57
Simple k-mers algorithms (pattern count, frequent words and clump finding) in JS using little genoma snippets for test
// Problem: Count the number of times a string appears as a substring in a longer text.
function patternCount(text, pattern) {
if (!text || !pattern) return -1;
let textLength = text.length;
let k = pattern.length;
let count = 0;
for (let i = 0; i < (textLength - k + 1); i++) {
let kmer = text.substring(i, i + k);
@leandrosilva
leandrosilva / hashtable.js
Created October 12, 2018 01:10
A naive JS implementation of hashtable using Linear Probing to solve collisions
let HashTable = function() {
let entries = [];
this.put = (key, value) => {
let hashKey = hashCode(key);
let entry = entries[hashKey];
// Linear Probing
while (entry) {
if (entry && entry[0] === key) break;
@leandrosilva
leandrosilva / BinaryPrintHelper.cs
Created October 24, 2017 15:06
Print to a network printer over LPR/LPD protocol
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace CodeZone.Helpers.Async
{
public static class TaskHelper
@leandrosilva
leandrosilva / chuncks.js
Last active April 11, 2016 19:35
Split a JavaScript Array into chuncks
Object.defineProperty(Array.prototype, 'chunk', {
value: function(chunkSize) {
var R = [];
for (var i=0; i<this.length; i+=chunkSize)
R.push(this.slice(i,i+chunkSize));
return R;
}
});
Array.range(10).chunk(3);
#!/usr/bin/env ruby
require "csv"
require "net/http"
require "date"
require "json"
#
# Get log data
#
package br.com.mamutelanoso;
import java.io.IOException;
import java.util.Properties;
import javax.mail.BodyPart;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;