Skip to content

Instantly share code, notes, and snippets.

View zhum's full-sized avatar

Zhumatiy Sergey zhum

View GitHub Profile
@zhum
zhum / gist:5865085
Created June 26, 2013 06:06
ruby class for openssh keys checking.
class OpenSSHKey
def self.valid? key
string=key.to_s
oneliner = string.lines.count>1 ? to_openssh(string) : string
tmpfile="/tmp/openssh-check-#{rand(1000000).to_i}"
File.open(tmpfile, "w") { |file| file.puts oneliner}
begin
system "ssh-keygen -l -f '#{tmpfile}' >/dev/null 2>/dev/null"
@zhum
zhum / json_or_jsonp
Created September 19, 2014 05:44
json_or_jsonp - great helper
def json_or_jsonp( json )
callback = params.delete('callback')
if callback
content_type :js
response = "#{callback}(#{json})"
else
content_type :json
response = json
end
@zhum
zhum / osmradio.sh
Last active August 29, 2015 14:07 — forked from Zverik/osmradio.sh
#!/usr/bin/sh
# PulseAudio setup for recording osm radio from skype and mic
function rec_start() {
IP=127.0.0.1
PASSWORD=password
DATE=$(date +%y%m%d-%H%M)
# Initializing microphone
MIC_ID=$(pactl list short sources|grep GoMic|grep input|cut -f 1)
@zhum
zhum / interfaces and references
Created March 3, 2015 13:04
interfaces and references example
package main
import "log"
type A interface {
SetId(string)
}
type B struct{
Afield A
@zhum
zhum / go-sort-insert.go
Created April 30, 2015 09:38
Golang function to insert in sorted array
// Mytype must implement Less func.
func SortedInsert (s []Mytype, f Mytype) []Mytype {
l:=len(s)
if l==0 { return [f] }
i := sort.Search(l, func(i int) bool { return s[i].Less(f)})
if i==l { // not found = new value is the smallest
return append([f],s)
}
@zhum
zhum / pifm.c
Created April 7, 2016 10:56
FM transmitter in C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <math.h>
#include <fcntl.h>
#include <assert.h>
#include <malloc.h>
#include <sys/mman.h>
#include <sys/types.h>
@zhum
zhum / dnsbl.sh
Created November 12, 2017 08:34 — forked from agarzon/dnsbl.sh
DNS Black List - Linux shell script (improved from: http://www.daemonforums.org/showthread.php?t=302)
#!/bin/sh
# Check if an IP address is listed on one of the following blacklists
# The format is chosen to make it easy to add or delete
# The shell will strip multiple whitespace
BLISTS="
bl.score.senderscore.com
bl.mailspike.net
bl.spameatingmonkey.net
b.barracudacentral.org
require 'dry-validation'
schema = Dry::Validation.Schema do
required(:field_1).filled(:str?)
required(:field_2).filled(:int?)
rule(field_2_depends_on_field_1: [:field_1, :field_2]) do |field_1, field_2|
field_1.eql?('Foo').then(field_2.eql?(0)) & field_1.eql?('Bar').then(field_2.eql?(1))
end
end
@zhum
zhum / Gemfile
Created March 21, 2018 08:03
rom test for dynamic class
source 'https://rubygems.org'
gem 'rom'
gem 'rom-sql'
gem 'rom-yaml', '2.0.0.rc2'
gem 'sqlite3'
# TURN OFF HDMI if not in use
# Get the current video output type and strip away the unimportant bits
video="$(tvservice -s | sed "s/^.*\[\([^ ]*\) .*$/\1/" )"
if [ "$video" != "HDMI" ]; then
printf "HDMI not detected. Turning off.\n"
tvservice -off > /dev/null
else
printf "HDMI detected.\n"
fi