Skip to content

Instantly share code, notes, and snippets.

View sap1ens's full-sized avatar

Yaroslav Tkachenko sap1ens

View GitHub Profile
@sap1ens
sap1ens / extend.js
Created April 24, 2012 16:11
Truly JavaScript inheritance
function extend(subClass, superClass) {
var F = function() {};
F.prototype = superClass.prototype;
subClass.prototype = new F();
subClass.prototype.constructor = subClass;
subClass.superclass = superClass.prototype;
if(superClass.prototype.constructor == Object.prototype.constructor) {
superClass.prototype.constructor = superClass;
}
}
@sap1ens
sap1ens / jquery.ba-tinypubsub.js
Created April 25, 2012 04:56 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
@sap1ens
sap1ens / backbone-custom-method.js
Created February 1, 2013 16:35
Adding Backbone.js custom REST method
var MyModel = Backbone.Model.extend({
someMethod: function(opts) {
var url = this.url() + '/someMethod',
// note that these are just $.ajax() options
options = {
url: url,
type: 'POST'
};
// add any additional options, e.g. a "success" callback or data
@sap1ens
sap1ens / phpunit.ant.build.xml
Created March 16, 2013 14:15
Easiest PHPUnit - Jenkins integration (Ant build & JUnit reports)
<project name="Test" default="test" basedir=".">
<target name="test">
<exec executable="phpunit" failonerror="true" />
</target>
</project>
@sap1ens
sap1ens / update.md
Last active November 14, 2017 23:16
Update Git remote branches on local machine
  1. git remote update --prune
  2. git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 &lt;(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
@sap1ens
sap1ens / build.sbt
Created February 22, 2014 01:22
Custom sbt-assembly merge strategy (fixes for spring, cglib, mockito)
val customMergeStrategy: String => MergeStrategy = {
case x if Assembly.isConfigFile(x) =>
MergeStrategy.concat
case PathList(ps @ _*) if Assembly.isReadme(ps.last) || Assembly.isLicenseFile(ps.last) =>
MergeStrategy.rename
case PathList("META-INF", xs @ _*) =>
(xs map {_.toLowerCase}) match {
case ("manifest.mf" :: Nil) | ("index.list" :: Nil) | ("dependencies" :: Nil) =>
MergeStrategy.discard
case ps @ (x :: xs) if ps.last.endsWith(".sf") || ps.last.endsWith(".dsa") =>
@sap1ens
sap1ens / CORSSupport.scala
Created November 10, 2014 02:08
CORS support for Spray-based APIs
package co.bench.api.spray
import spray.routing.{Directives, Route}
import spray.http.HttpHeaders.{`Access-Control-Allow-Credentials`, `Access-Control-Allow-Headers`, `Access-Control-Allow-Methods`, `Access-Control-Allow-Origin`}
import spray.http.{StatusCodes, HttpOrigin, SomeOrigins}
import spray.http.HttpMethods._
trait CORSSupport extends Directives {
private val CORSHeaders = List(
@sap1ens
sap1ens / ebs-snapshot-for-volume.sh
Last active November 18, 2020 06:01
Bash script for Automatic EBS Volume Snapshots and Cleanup on Amazon Web Services. Original - https://github.com/CaseyLabs/aws-ec2-ebs-automatic-snapshot-bash
#!/bin/bash
# Original was modified to do backup only for one specified volume.
set -ue
set -o pipefail
export PATH=$PATH:/usr/local/bin/:/usr/bin
## START SCRIPT
@sap1ens
sap1ens / gist:a426fe1067f49192b94f
Created December 17, 2015 21:00
eb-versions-cleanup.sh
#!/bin/bash
_appName=$1
_limit=$2
echo "$(date) checking app:$_appName with limit:$_limit "
# get app versions above the limit as a list
versions=$(aws elasticbeanstalk describe-application-versions\
--application-name $_appName\