Skip to content

Instantly share code, notes, and snippets.

View marcusdb's full-sized avatar

Marcus David Bronstein marcusdb

  • porto, Portugal
View GitHub Profile
@Stuff90
Stuff90 / observable-recursive.js
Last active May 7, 2022 02:53
Example of a recursive call to an API using Observables
// Example for article : https://medium.com/@simonb90/appels-api-itératifs-avec-rxjs-a1c2593c558b
/*
* Definition of API method:
* getEntitiesByPage(page: number): Observable<Entity[]>
*/
let iterator = new BehaviorSubject<number>(1);
iterator.mergeMap((i) => {
function isPromise(thing) {
return (
typeof thing === "object" && thing !== null
&& thing.then instanceof Function
&& thing.catch instanceof Function
);
}
function whileGenerates(gen, prevGenResult) {
@mdwhatcott
mdwhatcott / custom_json.go
Created July 29, 2015 17:15
Example of implementing MarshalJSON and UnmarshalJSON to serialize and deserialize custom types to JSON in Go. Playground: http://play.golang.org/p/7nk5ZEbVLw
package main
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
)
func main() {
@csamsel
csamsel / Enhanced NGINX logstash parser
Last active February 5, 2022 14:54
Enhanced NGINX logstash parser to include upstream response time and request length fields
Enhanced NGINX logstash parser:
NGINX log format:
log_format enhanced '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_length "$http_referer" "$http_user_agent" $request_time $upstream_response_time';
access_log /var/log/nginx/access.log enhanced;
error_log /var/log/nginx/error.log;
logstash pattern (/opt/logstash/pattern/nginx):
@rothgar
rothgar / main.yml
Last active April 28, 2025 04:18
Generate /etc/hosts with Ansible
# Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source.
# Will include all hosts the playbook is run on.
# Inspired from http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html
- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']
@mariussoutier
mariussoutier / Mail.scala
Created August 23, 2012 12:13
Sending mails fluently in Scala
package object mail {
implicit def stringToSeq(single: String): Seq[String] = Seq(single)
implicit def liftToOption[T](t: T): Option[T] = Some(t)
sealed abstract class MailType
case object Plain extends MailType
case object Rich extends MailType
case object MultiPart extends MailType
@worthlesscog
worthlesscog / gist:3060273
Created July 6, 2012 13:53
Polymorphic JSON unmarshall with Jackson in Scala
import org.codehaus.jackson.annotate.{ JsonTypeInfo, JsonSubTypes, JsonProperty }
import org.codehaus.jackson.annotate.JsonSubTypes.Type
import org.codehaus.jackson.map.ObjectMapper
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes(Array(
new Type(value = classOf[Bingo], name = "x"),
new Type(value = classOf[Bongo], name = "y"),
new Type(value = classOf[Bungo], name = "z")
))
@stevegury
stevegury / Console log
Created March 30, 2012 17:16
Finagle MySQL codec in action
import com.twitter.finagle.mysql._
import java.net.InetSocketAddress
val login = "stevegury"
val client = MySQLClient(new InetSocketAddress("localhost", 3306), login, password)
val query = for {
_ <- client.use("my_db")
res <- client.query("select * from my_table")
@THemming
THemming / gist:2173037
Created March 23, 2012 17:31
init.d script to launch Play framework under CentOS/RedHat
#!/bin/bash
# chkconfig: 345 20 80
# description: Play start/shutdown script
# processname: play
#
# Instalation:
# copy file to /etc/init.d
# chmod +x /etc/init.d/play
# chkconfig --add /etc/init.d/play
# chkconfig play on
@zilkey
zilkey / ember-precompile.js
Created March 10, 2012 22:30 — forked from garth/Jakefile.js
Precompile .handlebars templates with node js
var fs = require('fs');
var vm = require('vm');
var emberjs = fs.readFileSync('public/javascripts/vendor/ember-0.9.5.min.js', 'utf8');
var templatesDir = 'templates';
var destinationDir = 'public/javascripts/templates';
function compileHandlebarsTemplate(templatesDir, fileName) {
var file = templatesDir + '/' + fileName;