Skip to content

Instantly share code, notes, and snippets.

@SergKolo
SergKolo / scratch.java
Created September 15, 2015 17:04
Lottery. Generate 6 random numbers untill they match your guess. Do this until you hit jackpot. Once you hit jackpot , repeat that 25 times.
import java.lang.Math;
import java.util.Random;
import java.util.Arrays;
public class scratch
{
public static void main ( String [] args )
{
int lottoNums[] = new int [6];
int myNums[] = {1,13,15,22,41,36};
@SergKolo
SergKolo / golf.py
Last active March 16, 2016 18:44
A recursive solution to Checkio task
# A recursive solution to https://github.com/Bryukh-Checkio-Tasks/checkio-task-stair-steps/blob/master/info/task_description.html
def golf(nums,skipped):
if nums:
x = nums.pop(0) # grab current number
if x < 0 and not skipped: # is this one negative ?
print 'Skipping',x
return golf(nums[0:],True) # then skip
else:
print 'returning',x
return x+golf(nums[0:],False) # otherwise, don't skip
@SergKolo
SergKolo / get_unity_viewports.sh
Created April 23, 2016 18:36
Short script to associate coordinates and positional numbers of viewports through an array
$> cat viewports.sh
#!/bin/bash
get_screen_geometry()
{
xwininfo -root | awk '/-geometry/{gsub(/+|x/," ");print $2,$3}'
}
SCHEMA="org.compiz.core:/org/compiz/profiles/unity/plugins/core/"
read screen_width screen_depth <<< "$(get_screen_geometry)"
@SergKolo
SergKolo / xprop_windows.sh
Created April 24, 2016 03:15
Getting windows with xprop
get_hex_xids()
{
xprop -root -notype _NET_CLIENT_LIST | \
awk 'BEGIN{printf "ibase=16"}\
{gsub(/\,/," ");for(i=1;i<=NF;i++) \
if ($i~/0x/) printf ";%s",substr(toupper($i),3) }'
}
convert_hex2dec()
{
@SergKolo
SergKolo / window_stack
Created April 24, 2016 03:41
Get Unity's window stack
window_stack()
{
qdbus --literal com.canonical.Unity.WindowStack
/com/canonical/Unity/WindowStack \
com.canonical.Unity.WindowStack.GetWindowStack | \
awk -F '{' '{gsub(/\}|\]|,/,"");gsub(/\[/,"\n");print $2}' | \
awk '!/compiz/&&!/^$/ && $4!="\""$3"\"" { L[n++] = $0 }\
END { while(n--) print L[n] }'
}
DIR:/xieerqi|16:06|skolodya@ubuntu:
$ cat monitor_stack.sh
get_monitor_stack()
{
qdbus org.ayatana.bamf \
/org/ayatana/bamf/matcher \
org.ayatana.bamf.matcher.WindowStackForMonitor $1
}
for window in $( get_monitor_stack $1 )
#!/bin/bash
list_windows()
{
# get list of all currently open windows
qdbus org.ayatana.bamf \
/org/ayatana/bamf/matcher \
org.ayatana.bamf.matcher.WindowPaths
}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gi.repository import Gio,Notify
import dbus
import sys
import os
import time
import subprocess
def get_dbus(bus_type,obj,path,interface,method,arg):
#!/bin/bash
# We want to find the directory where all the backlight data
# is stored , based on the fact that there's always "actual_brightness"
# file in that directory
DIR=$(find /sys/devices/ -type f -name "actual_brightness" -printf "%h" )
# Graphic cards all have different integer value for
# maximum level of brightness, so we need to get it
MAX=$(cat "$DIR"/max_brightness )
from gi.repository import GdkX11,Gdk
import subprocess
import time
def run_sh(cmd):
# run shell commands
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
out = p.stdout.read().strip()
return out