Skip to content

Instantly share code, notes, and snippets.

View Farzy's full-sized avatar

Farzad FARID Farzy

View GitHub Profile
// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
// See page 20.
//!+
// Server2 is a minimal "echo" and counter server.
package main
import (

Keybase proof

I hereby claim:

  • I am farzy on github.
  • I am farzad (https://keybase.io/farzad) on keybase.
  • I have a public key ASDGWND5gUrYGfJ6DIHefYpxOxLQ4tqfK8RA268kDFn4hgo

To claim this, I am signing this object:

myMap :: (a -> b) -> [a] -> [b]
myMap f [] = []
myMap f (x:xs) = f x : myMap f xs
-- > myMap (+2) [1..3]
-- [3,4,5]
@Farzy
Farzy / config_file.pp
Created April 6, 2015 17:21
Puppet define config_file
# Define a config file than can be an usual source, or a template URL: template:///
define config_file($path = false, $source = false, $mode, $owner, $group) {
file {"$title":
mode => $mode,
owner => $owner,
group => $group,
}
if $path {
File["$title"]{
path => $path,
@Farzy
Farzy / getswap2
Created February 19, 2015 17:19
getswap
#!/bin/bash
# find-out-what-is-using-your-swap.sh
# -- Get current swap usage for all running processes
# --
# -- rev.0.3, 2012-09-03, Jan Smid - alignment and intendation, sorting
# -- rev.0.2, 2012-08-09, Mikko Rantalainen - pipe the output to "sort -nk3" to get sorted output
# -- rev.0.1, 2011-05-27, Erik Ljungstrom - initial version
@Farzy
Farzy / getswap
Created February 19, 2015 17:18
getswap
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
# Modified by Mikko Rantalainen 2012-08-09
# Pipe the output to "sort -nk3" to get sorted output
SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"`
do
PID=`echo $DIR | cut -d / -f 3`
@Farzy
Farzy / gist:2214522
Created March 27, 2012 09:58
zbx_api/zabcon gruik code
#Somewhere in the 1.8.x cycle it was decided to do deprecate with user.authenticate
#however it was not documented well, so we will try uer.login first, and fall
#back to user.authenticate as user.login does not exist in 1.8.3
login_methods=["user.login","user.authenticate"]
begin
result = do_request(json_obj(login_methods.first,{'user'=>l_user,'password'=>l_password}))
@auth=result['result']
#setup the version variables
@Farzy
Farzy / irb3.rb
Created October 31, 2011 15:15 — forked from peterc/irb3.rb
irb3 - Run an IRB-esque prompt over multiple Ruby implementations at once using RVM
#!/usr/bin/env ruby
# encoding: utf-8
# irb3 - Runs an IRB-esque prompt (but it's NOT really IRB!) over multiple
# versions of Ruby at once (using RVM)
#
# By Peter Cooper, BSD licensed
#
# Main dependency is term-ansicolor for each impl:
# rvm exec gem install term-ansicolor
@Farzy
Farzy / zshrc.sh
Created July 16, 2011 11:34
Generate a correct SSH_AUTH_SOCK variable in a reconnected "screen" shell
# Cette fonction permet de récupérer dans un screen détaché et réattaché
# la connexion à l'agent d'authentification SSH ainsi que le DISPLAY X11
# s'il a été défini (respectivement "ssh -A" et "ssh -X").
function ssh-screen-auth() {
# Variables locales dont un tableau
local SCREENPID SOCK DISP
local -a SCREENPIDS
# Cherche le pid de screen et vérifie qu'il n'y a qu'un seul screen,
# s'il y en a plusieurs on ne sait pas les choisir.
SCREENPIDS=($(pgrep -f "screen -(r|dr|DR)" -u $UID))
@Farzy
Farzy / gist:946389
Created April 28, 2011 13:54
Running chef init script with a ruby provided by RVM
We couldn’t find that file to show.