Skip to content

Instantly share code, notes, and snippets.

@marioosh
marioosh / Server.scala
Created May 20, 2016 08:46
Basic akka-http server
package io.scalac.conductr.example
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Sink, Source}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
@mlovic
mlovic / mocks_and_stubs.md
Last active June 1, 2020 16:24
Difference between mocks and stubs using ruby with mocha library

This gist aims to explain the difference between stubs and mocks and when each should be used. For an introduction to stubs and mocks, start somewhere else, like here.

 

  • Stub: used to isolate the object under test from its dependencies, preventing the test from being influenced by code outside the object. This way the test can't be made to fail or be broken by code which is not part of the specific functionality being tested. Stubs also lead to less code being run, which helps keep tests fast. A stub has no expectations. It doesn't care if it is called or how many times.

    For example, you might stub out a message sent to a database connection if all you are trying to test is the type of the method's return value.

 

@jswanner
jswanner / migrate.rake
Last active April 1, 2021 22:05
Rolls back migrations in current branch not present in specified branch.
desc 'rolls back migrations in current branch not present in other'
task :rollback_branch_migrations, [:other_branch] do |t, args|
load "#{Dir.pwd}/Rakefile"
branch_migrations = BranchMigrations.new(args.other_branch)
puts ['Rollback the following migrations', branch_migrations, 'y,n? ']
next if %w[no n NO N].include?(STDIN.gets.chomp)
Rake::Task['environment'].invoke
@krambertech
krambertech / Component.jsx
Created July 2, 2016 10:44
ReactJS: Input fire onChange when user stopped typing (or pressed Enter key)
import React, { Component } from 'react';
import TextField from 'components/base/TextField';
const WAIT_INTERVAL = 1000;
const ENTER_KEY = 13;
export default class TextSearch extends Component {
constructor(props) {
super();

Business Logic / Domain Model structures for Ruby, Rails

@rtomayko
rtomayko / optparse-template.rb
Last active June 3, 2023 03:16
Ruby optparse template
#!/usr/bin/env ruby
#/ Usage: <progname> [options]...
#/ How does this script make my life easier?
# ** Tip: use #/ lines to define the --help usage message.
$stderr.sync = true
require 'optparse'
# default options
flag = false
option = "default value"
@joyrexus
joyrexus / README.md
Last active August 21, 2023 16:59
Node.js streams demystified

A quick overview of the node.js streams interface with basic examples.

This is based on @brycebaril's presentation, Node.js Streams2 Demystified

Overview

Streams are a first-class construct in Node.js for handling data.

Think of them as as lazy evaluation applied to data.

@Unbinilium
Unbinilium / Get-started-with-OpenCV-CUDA-cpp.md
Last active October 30, 2023 05:59
Get started with OpenCV CUDA C++

First your OpenCV should be compiled with CUDA (and OpenGL) support to test all this features. Detect your CUDA hardware with OpenCV CUDA by:

#include <iostream>
using namespace std;

#include <opencv2/core.hpp>
using namespace cv;

#include <opencv2/cudaarithm.hpp>
using namespace cv::cuda;
@remarkablemark
remarkablemark / README.md
Last active November 12, 2023 07:52
Classes - ES5 vs ES6

JavaScript Classes - ES5 vs ES6

An example that shows the difference between creating a JavaScript class and subclass in ES5 and ES6.

Reference

<template lang='pug'>
div.drop-zone(:class='{dragging: isDragging }'
@dragover.prevent='dragover'
@dragenter.prevent='dragover'
@drop.prevent.stop='onDrop'
@dragleave.prevent='dragleave')
div(:class='{ hidden: uploadInProgress }' @click='openFileBrowser')
slot
i {{label}}
input(type='file' :multiple='multiple' ref='input' style='display: none')