Skip to content

Instantly share code, notes, and snippets.

View nyukhalov's full-sized avatar
🚀
to infinity and beyond

Roman Niukhalov nyukhalov

🚀
to infinity and beyond
View GitHub Profile
@ldoguin
ldoguin / CouchbaseContainer.java
Created July 26, 2016 12:26
Couchbase Container for the TestContainers project
package org.testcontainers.containers;
import com.couchbase.client.core.utils.Base64;
import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
import org.testcontainers.containers.traits.LinkableContainer;
import org.testcontainers.containers.wait.HttpWaitStrategy;
import java.io.DataOutputStream;
@owainlewis
owainlewis / ApplicationController.scala
Last active March 27, 2019 11:30
Play Framework Basic Auth Action (play, scala, basic auth)
class ControllerWithBasicAuth extends Controller {
private val WithBasicAuth = new BasicAuthAction("user", "pass")
def index = WithBasicAuth {
Ok("Correct basic auth credentials")
}
}
@m5m1th
m5m1th / localPorts.sh
Last active May 27, 2020 04:57
Redirect port 3080/3443 to 80/443 for local dev
#Requests from outside
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3080
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 3443
#Requests from localhost
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 3080
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 443 -j REDIRECT --to-ports 3443
@ihorvorotnov
ihorvorotnov / get-social-shares
Last active October 20, 2020 12:15
Get number of shares from social platforms
Facebook*:
https://api.facebook.com/method/links.getStats?urls=%%URL%%&format=json
+ works, returns shares, likes, comments and total
Twitter:
http://urls.api.twitter.com/1/urls/count.json?url=%%URL%%&callback=twttr.receiveCount
+ v1 API but still works
Reddit:
http://buttons.reddit.com/button_info.json?url=%%URL%%
@bmaeser
bmaeser / subtitle-extract.txt
Created September 2, 2011 23:25
extract subtitles from *.mkv-files on osx
lines with $ are commands
### install mkvtoolnix:
$ brew install mkvtoolnix
### list content of the mkv-file:
$ mkvmerge -i mymoviefile.mkv
### what will give you:
@mriddle
mriddle / jenkins_copying_configuration.sh
Created November 9, 2012 03:13
Moving Jenkins server configuration from one server to another
ORIGINAL_JENKINS_SERVER=
ORIGINAL_SERVER_USER=
NEW_JENKINS_SERVER=
NEW_SERVER_USER=
# ON THE ORIGINAL JENKINS SERVER
ssh $ORIGINAL_SERVER_USER@$ORIGINAL_JENKINS_SERVER
cd /var/lib/jenkins/
for i in `ls jobs`; do echo "jobs/$i/config.xml";done > config.totar
@RayRoestenburg
RayRoestenburg / firstSucceededOf.scala
Last active May 20, 2021 21:45
firstSucceededOf, returns a future containing the first successful result or contains the last failure if all futures have failed. What's wrong with it?
import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util._
import java.util.concurrent.atomic.AtomicInteger
def firstSucceededOf[T](futures: TraversableOnce[Future[T]])(implicit executor: ExecutionContext): Future[T] = {
val p = Promise[T]()
val size = futures.size
val failureCount = new AtomicInteger(0)
@danswick
danswick / README.md
Last active December 26, 2022 04:05
Indoor map example

Using a hypothetical museum floorplan to demonstrate hover and click interactivity, as well as fitBounds.

@noelwelsh
noelwelsh / loop.scala
Created October 15, 2015 16:18
Example of monadic loop using the State monad in Cats
import cats.{Id,Monad}
import cats.state.State
import cats.std.function._
import scala.language.higherKinds._
// Call Example.example.run to see the example running
object Example {
type MyState[A] = State[Int, A]
@viktorklang
viktorklang / Future-retry.scala
Last active July 23, 2023 23:48
Asynchronous retry for Future in Scala
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import akka.pattern.after
import akka.actor.Scheduler
/**
* Given an operation that produces a T, returns a Future containing the result of T, unless an exception is thrown,
* in which case the operation will be retried after _delay_ time, if there are more possible retries, which is configured through
* the _retries_ parameter. If the operation does not succeed and there is no retries left, the resulting Future will contain the last failure.