Skip to content

Instantly share code, notes, and snippets.

View zarinfam's full-sized avatar

Saeed Zarinfam zarinfam

View GitHub Profile
@pjkelly
pjkelly / setup-vmware-image-with-static-IP.markdown
Created July 7, 2011 01:06
VMWare Fusion Images with a static IP Address on Mac OS X Snow Leopard

How to setup your VMWare Fusion images to use static IP addresses on Mac OS X

At Crush + Lovely, we use Railsmachine's Moonshine to automate the configuration of our servers. When writing our deployment recipes, VMWare Fusion's ability to take snapshots and rollback to these snapshots is a huge timesaver because it takes just seconds to roll a server image to it's original state.

When you're just configuring a single server, having a static IP address for your server image isn't too important, but when you're configuring multi-server setups, it can be useful to duplicate a number of server images and give each a static IP address so you can consistently deploy to them. While not documented well at all, it turns out that this is relatively easy to accomplish in four simple steps.

1. Determine the MAC address of your guest machine

Let's say you have a guest machine with the name ubuntu-lucid-lynx-base a

@aeris
aeris / clip.py
Created August 9, 2012 23:21
Copy/paste from command line with Klipper
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
import argparse, dbus, sys
bus = dbus.SessionBus()
klipper = bus.get_object('org.kde.klipper', '/klipper')
@emil2k
emil2k / Connectivity.java
Last active December 22, 2023 06:03
Android utility class for checking device's network connectivity and speed.
/*
* Copyright (c) 2017 Emil Davtyan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@stopher
stopher / ByteRangeRequestsController.java
Last active December 7, 2017 16:40
Byte range requests in Play 2 Java Controllers. Eg. for serving MP4 video files to iPhone etc.
public class ByteRangeRequestsController extends Controller {
// 206 Partial content Byte range requests
private static Result stream(long start, long length, File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
fis.skip(start);
response().setContentType(MimeTypes.forExtension("mp4").get());
response().setHeader(CONTENT_LENGTH, ((length - start) +1l)+"");
response().setHeader(CONTENT_RANGE, String.format("bytes %d-%d/%d", start, length,file.length()));
@mgodave
mgodave / futures.kt
Created November 14, 2013 04:35
Akka Futures API in Kotlin (for fun)
import com.google.common.util.concurrent.ListeningExecutorService
import com.google.common.util.concurrent.MoreExecutors
import java.util.concurrent.Executors
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.FutureCallback
import com.google.common.util.concurrent.SettableFuture
import java.util.ArrayList
object KFutures {
public class ByteRangeRequestsController extends Controller {
// 206 Partial content Byte range requests
private static Result stream(long start, long length, File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
fis.skip(start);
response().setContentType(MimeTypes.forExtension("mp4").get());
response().setHeader(ACCEPT_RANGES, "bytes");
response().setHeader(CONNECTION, "keep-alive");
@yassermzh
yassermzh / AngularJS Setup
Last active August 29, 2015 14:04
Simple setup to start playing with AngularJS. Used the instructions from https://github.com/startup-class/setup/blob/master/setup.sh
#!/bin/bash
# Install nvm: node-version manager
# https://github.com/creationix/nvm
sudo apt-get install -y git
wget https://raw.github.com/creationix/nvm/master/install.sh
sh install.sh
# TEST: now this should work
nvm
@rompetroll
rompetroll / Compile.java
Last active May 13, 2017 06:36
java8 lambdas and exceptions
import java.util.function.Function;
import java.util.Optional;
public class Compile {
private <F,T> T runFun(Function<Optional<F>, T> fun, Optional<F> opt) {
return fun.apply(opt) ;
}
public void foo() {
Function<Optional<String>, String> fun = o -> o.orElseThrow(() -> new RuntimeException("nah"));
the 'repackage' command creates a distributable box file from the unpacked box in your ~/.vagrant.d/boxes directory.
Let's say you "vagrant box add" a box named centos.box from an URL
vagrant will extract centos.box in your vagrant home folder (the box format is just a tar file)
in my case ~/.vagrant.d/boxes/centos
In that folder you will see files like :
[root@goll tmp]# ls ~/.vagrant.d/boxes/centos65/0/virtualbox/
box-disk1.vmdk box.ovf metadata.json Vagrantfile
@fancellu
fancellu / TryFlatten.scala
Created April 11, 2017 00:44
A few ways to flatten down a Seq[Try] to only Success values
import scala.util.{Success, Failure}
val seq=Seq(Success(1), Failure(new Exception("bang")), Success(2))
// all emit List(1, 2)
seq.map(_.toOption).flatten
seq.flatMap(_.toOption)
seq.filter(_.isSuccess).map(_.get)
seq.collect{case Success(x) => x}