Skip to content

Instantly share code, notes, and snippets.

View zarinfam's full-sized avatar

Saeed Zarinfam zarinfam

View GitHub Profile
@djkeh
djkeh / BootApplication.java
Last active November 23, 2021 20:53 — forked from seanhinkley/BootApplication.java
Spring Boot 1.5.4.RELEASE + Thymeleaf 3.0.7.RELEASE (Gradle)
package com.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
@SpringBootApplication(exclude = ThymeleafAutoConfiguration.class)
public class BootApplication {
public static void main(String[] args) {
SpringApplication.run(AppSecurityApplication.class, args);
@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}
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
@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"));
@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
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");
@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 {
@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()));
@emil2k
emil2k / Connectivity.java
Last active August 5, 2024 10:48
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:
@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')