Skip to content

Instantly share code, notes, and snippets.

View tovbinm's full-sized avatar
⌨️
<typing sounds>

Matthew Tovbin tovbinm

⌨️
<typing sounds>
View GitHub Profile
@tovbinm
tovbinm / .backupignore
Created February 26, 2014 19:33
Backup Mac using rsync
.Spotlight-*/
.Trashes
/afs/*
/automount/*
/cores/*
/dev/*
/Network/*
/private/tmp/*
/private/var/run/*
/private/var/spool/postfix/*
@tovbinm
tovbinm / waves.js
Created January 26, 2014 05:24
Breaking waves sound (Open (http://myjavatools.com/js.html) in Chrome paste the code and hit run)
var AMP = 0.5; // amplitude
var len = 15; // seconds
e = new webkitAudioContext();
var source = e.createBufferSource();
var SR = e.sampleRate;
source.buffer = e.createBuffer(1, len * SR, SR);
var dat = source.buffer.getChannelData(0);
for (var i = 0; i < len * SR; i++) {
dat[i] = AMP * (Math.random() * 2 - 1);
}
@tovbinm
tovbinm / Build.scala
Created January 21, 2014 00:49
Kafka 0.8.0 with Zookeeper 3.4.5
<dependency org="org.apache.zookeeper" name="zookeeper" rev="3.4.5">
<exclude org="log4j" module="log4j"/>
<exclude org="org.slf4j" module="slf4j-log4j12"/>
<exclude org="jline" module="jline"/>
</dependency>
@tovbinm
tovbinm / Id64.scala
Last active January 20, 2017 09:55
64 bit unique id generator
import scala.util.Random
import java.security.SecureRandom
import java.util.concurrent.atomic.AtomicLong
import org.joda.time.DateTimeUtils
/**
* 64 bit unique id generator
* Features:
* 1. generate ascending or descending ids
* 2. 64 bit id consists of:
@tovbinm
tovbinm / ch5_streams.scala
Last active December 26, 2015 13:59
Reading Functional Programing In Scala
// Excercies from chapter 5: Strictness and laziness
def foldRight[A,B](z: => B)(s: Stream[A])(f: (A, => B) => B): B =
s match {
case hd #:: tail => f(hd, foldRight(z)(tail)(f))
case _ => z
}
def exists[A](s: Stream[A])(p: A => Boolean): Boolean =
foldRight(false)(s)((x,a) => if (p(x)) true else a)
@tovbinm
tovbinm / gist:6498848
Created September 9, 2013 17:30
Backup/Restore with MySQL
DB=my_db
mysqldump -uroot -h localhost $DB --opt --compress | gzip -9 -c > $DB-backup-`date +%Y%m%d%H`.sql.tgz
gunzip -c $DB-backup-`date +%Y%m%d%H`.sql.tgz > a.sql
mysql -u root $DB < a.sql
@tovbinm
tovbinm / resize.rb
Last active December 20, 2015 22:39
S3 Resize images
require 'aws/s3'
require 'RMagick'
include AWS::S3
include Magick
AWS::S3::Base.establish_connection!(
:access_key_id => 'key',
:secret_access_key => 'secret'
)
bucket = 'bucket_name';
@tovbinm
tovbinm / gist:6086013
Created July 26, 2013 03:50
NTFS Write Support On OS X Mountain Lion
If you have noticed, Mac OS X doesn’t support writing onto NTFS disks. But not to worry, you don’t have to install any third party drivers to enable this. Mountain Lion 10.8.3 already has native write support for the NTFS. OSX Mountain Lion does have built-in support for NTFS, and it can read and write. However, Apple does not enable it by default.
Here is what you should do:
Uninstall other 3rd-party NTFS software, like Paragon, Tuxera or NTFS-3G.
Edit /etc/fstab (you can do this with “sudo vi /etc/fstab”)
Add the following line:
LABEL=”VOLUME_NAME_WITHOUT_QUOTES” none ntfs rw,auto,nobrowse
Quit your editor
Now, just unmount and re-mount the disk
@tovbinm
tovbinm / gist:5482957
Created April 29, 2013 16:53
Setup Apache + Ruby on Rails + Passenger on Debian
apt-get update
apt-get install vim git
apt-get install libcurl4-openssl-dev
apt-get install apache2-prefork-dev
apt-get install libapr1-dev
apt-get install libaprutil1-dev
bash -s master < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
echo '[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"' >> ~/.bashrc
echo 'PATH=$PATH:/usr/local/rvm/bin' >> ~/.bashrc
@tovbinm
tovbinm / gist:4507146
Last active December 10, 2015 23:08
Searching photo caption and filtering by owner's gender
curl -XDELETE 'http://localhost:9200/test/'
curl -XPUT 'http://localhost:9200/test/' -d '{
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
},
"mappings" : {
"profile" : {
"properties" : {