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 / qdbus_windows.sh
Created April 24, 2016 03:19
listing apps and their windows with qdbus
#!/bin/bash
get_window_paths()
{
qdbus org.ayatana.bamf /org/ayatana/bamf/matcher org.ayatana.bamf.matcher.WindowPaths
}
get_running_apps()
{
qdbus org.ayatana.bamf /org/ayatana/bamf/matcher org.ayatana.bamf.matcher.RunningApplications
@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
#set -x
wait_ac_connect()
{
while ! on_ac_power ; do : ; sleep 0.25 ; done && echo PLUGGED_IN
}
wait_ac_disconnect()
{
while on_ac_power ; do : ; sleep 0.25 ; done && echo UNPLUGGED
#!/bin/bash
list_windows()
{
# get list of all currently open windows
qdbus org.ayatana.bamf \
/org/ayatana/bamf/matcher \
org.ayatana.bamf.matcher.WindowPaths
}
#!/bin/bash
# run script like so: bash thirds.sh NUMBER
# where NUMBER is 0,1 or 2
# 0 is left, 1 is center, 2 is right
get_screen_geometry()
{
# determine size of the desktop
xwininfo -root | \
awk -F ':' '/Width/{printf "%d",$2/3}/Height/{print $2}'
}