Skip to content

Instantly share code, notes, and snippets.

View cocodrino's full-sized avatar
🏠
Working from home

carlos L cocodrino

🏠
Working from home
  • Venezuela
View GitHub Profile
@cocodrino
cocodrino / futureOption.scala
Last active August 29, 2015 14:06
Future[Option[_] or Future[Option[_]]
import scala.reflect.runtime.universe._
//in A perfect world : without type erasure
implicit class SuperFuture (a : Future[Option[_]]){
def or (b : Future[Option[_]]) ={
a match {
case a1 : Future[Some[_]] => a1
case _ => b
}
}
@cocodrino
cocodrino / scalaYQL.scala
Last active August 29, 2015 14:06
YQL from scala
import scalaj.http.{HttpOptions, Http}
def YQL3(query: String) = {
val url = "http://query.yahooapis.com/v1/public/yql"
Future {
blocking {
Http(url).params("format" -> "xml", "q" -> query)
.option(HttpOptions.connTimeout(5000)) //Optional: yql can take a long time for response
.option(HttpOptions.readTimeout(10000)).asString
@cocodrino
cocodrino / shit2
Created January 14, 2015 18:57
remove trailing whitespaces from object in javascript (works recursively)
var fixKeys = function(obj) {
return Object.keys(obj).reduce(function(mem,key) {
if(Array.isArray(obj[key])){
mem[key.trim()] = obj[key].map(function(v){return v.trim()})
}else{
if(typeof obj[key] === 'object'){
mem[key.trim()] = fixKeys(obj[key])
}else{
mem[key.trim()] = (obj[key]).trim()
}
;;; -*- mode: emacs-lisp -*-
;;; This file is loaded by Spacemacs at startup.
;25.1.50.2
;;; It must be stored in your home directory.
(defun blah() (dotspacemacs/user-config))
;;(blah)
(defun dotspacemacs/user-config ()
"This is were you can ultimately override default Spacemacs configuration.
This function is called at the very end of Spacemacs initialization."
@cocodrino
cocodrino / spacemacs.el
Last active March 2, 2019 13:51
spacemacs
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@cocodrino
cocodrino / asda.bash
Created August 27, 2017 22:15
get size folders inside the current location
sudo ls -1d */ | sudo xargs -I{} du {} -sh && sudo du -sh
rsync -avP FROM TO
-u, --update skip files that are newer on the receiver
@cocodrino
cocodrino / disk.bash
Created November 13, 2017 01:16
show excesive IO in disk
iotop -bktoqqq -d .5
where: -b is batch mode
-k is kilobytes/s
-t adds timestamp
-o only show processes or threads actually doing I/O
-qqq removes output headers
-d .5 updates every .5 seconds
Once you have the process id, you can also find the files with
@cocodrino
cocodrino / checkpage.sh
Created November 15, 2017 17:42
pagina up o mensaje correo
/usr/bin/wget "www.example.com" --timeout 30 -O - 2>/dev/null | grep "Normal operation string" || echo "The site is down" | /usr/bin/mail -v -s "Site is down" your@e-mail.address
@cocodrino
cocodrino / file.sh
Created November 17, 2017 14:18
remove or add coments to line with some pattern in some file through command line...ideal for dockerfiles
comment is
sed -i '/<pattern>/s/^/#/g' file
And to uncomment it:
sed -i '/<pattern>/s/^#//g' file
In your case:
sed -i '/2001/s/^/#/g' file (to comment out)
sed -i '/2001/s/^#//g' file (to uncomment)