Skip to content

Instantly share code, notes, and snippets.

@sasajib
sasajib / create-thumbnails
Created April 7, 2020 02:17 — forked from johnnyg/create-thumbnails
Generate thumbnails and output media info
#!/bin/bash
parse_time() {
IFS=' ' read -ra PART <<< "$1"
seconds=0
for i in "${PART[@]}"; do
number=$(expr match $i '\([0-9]\+\)')
unit=$(expr match $i '[0-9]*\([a-z]\+\)')
case $unit in
h)
@sasajib
sasajib / LEPP.md
Created March 10, 2020 07:52 — forked from cham11ng/LEPP.md
LEPP Setup - Ubuntu 16.04 LTS

A Relatively Secure Server Stack Setup in Ubuntu 16.04 LTS

Anup Dhakal

Sagar Chamling

Introduction

In this guide, LEPP stands for Linux, Nginx (pronounced as Engine-X) , Postgres and PHP (PHP Hypertext Preprocessor).

@sasajib
sasajib / clean-up-boot-partition-ubuntu.md
Created October 16, 2018 22:24 — forked from ipbastola/clean-up-boot-partition-ubuntu.md
Safest way to clean up boot partition - Ubuntu 14.04LTS-x64

Safest way to clean up boot partition - Ubuntu 14.04LTS-x64

Reference

Case I: if /boot is not 100% full and apt is working

1. Check the current kernel version

$ uname -r 
@sasajib
sasajib / loop_aria2.sh
Created December 21, 2017 20:57 — forked from jonbakerfish/loop_aria2.sh
aria2 downloads a list of files, loop until all file are finished
#!/bin/bash
aria2c -j5 -i list.txt -c --save-session out.txt
has_error=`wc -l < out.txt`
while [ $has_error -gt 0 ]
do
echo "still has $has_error errors, rerun aria2 to download ..."
aria2c -j5 -i list.txt -c --save-session out.txt
has_error=`wc -l < out.txt`
sleep 10
@sasajib
sasajib / util.js
Last active September 19, 2017 18:56
Javascript Utils
//[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] => [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17]]
function grouped(arr, limit){
return arr.map((data, index) => {
return index % limit === 0 ? arr.slice(index, index + limit) : null;
}).filter((item) => { return item; })
}
//range crete [0,1,2,3,4...number]
function range(number){
return Array.from(new Array(number), (x,i) => i)
@sasajib
sasajib / run.sh
Created May 19, 2017 22:15 — forked from jakub300/run.sh
Compile headless shell (Chromium)
# Based on:
# http://www.zackarychapple.guru/chrome/2016/08/24/chrome-headless.html
# https://www.chromium.org/developers/how-tos/get-the-code
# https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
apt-get update
apt-get install -y curl git htop man unzip vim wget python
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=$PATH:`pwd`/depot_tools
mkdir Chromium && cd Chromium
@sasajib
sasajib / case_class.py
Created March 29, 2017 19:18 — forked from wickman/case_class.py
case-class like thing in python
# E.g. TaskClass = CaseClass('name', 'owner', 'pid')
# task1 = TaskClass(name = "hello", owner = "brian", pid = 15)
# task2 = TaskClass(name = "world", owner = "brian", pid = 13)
# tasks = [task1, task2]
#
# filter(lambda task: task.where(owner = "brian"), tasks) => [task1, task2]
# filter(lambda task: task.where(owner = "brian", pid = 13), tasks) => [task2]
#
# matcher = TaskClass(pid = 13)
# filter(lambda task: task.match(matcher), tasks) => [task2]
@sasajib
sasajib / AkkaStreamSparkIntegration.scala
Created March 11, 2017 20:09 — forked from lloydmeta/AkkaStreamSparkIntegration.scala
Example for how to connect Akka Stream and Spark Streaming by turning creating a Flow element that feeds into an InputDstream
import akka.actor._
import akka.stream.scaladsl.Flow
import org.apache.spark.streaming.dstream.ReceiverInputDStream
import org.apache.spark.streaming.receiver.ActorHelper
import akka.actor.{ ExtensionKey, Extension, ExtendedActorSystem }
import scala.reflect.ClassTag
object AkkaStreamSparkIntegration {
package tech.webstar.utils
import scala.collection.mutable
/**
* @author sasajib
*/
trait BoundedQueue[A] extends mutable.Queue[A] {
def maxSize: Int
override def +=(a: A): this.type = {
@sasajib
sasajib / gist:9f36b43f3340bf49ee434ff5ee92d6f5
Created February 27, 2017 00:32 — forked from ryanlecompte/gist:5746241
Bounded priority queue in Scala
import scala.collection.mutable
/**
* Bounded priority queue trait that is intended to be mixed into instances of
* scala.collection.mutable.PriorityQueue. By default PriorityQueue instances in
* Scala are unbounded. This trait modifies the original PriorityQueue's
* enqueue methods such that we only retain the top K elements.
* The top K elements are defined by an implicit Ordering[A].
* @author Ryan LeCompte ([email protected])
*/