Skip to content

Instantly share code, notes, and snippets.

View andy722's full-sized avatar

Andy Belsky andy722

  • as a private person here
  • Russia, Novosibirsk
View GitHub Profile
@andy722
andy722 / vbox-fwd-clr.bat
Created February 1, 2011 23:30
Port forwarding for VirtualBox VM
@echo off
set GUEST="Ubuntu 10.10 Server x86"
set MANAGE="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
%MANAGE% setextradata %GUEST% "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort"
%MANAGE% setextradata %GUEST% "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort"
%MANAGE% setextradata %GUEST% "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol"
@andy722
andy722 / fork_bomb
Created February 7, 2011 21:50
Bash fork bomb
:(){:|:;};:
@andy722
andy722 / miss.py
Created February 7, 2011 21:52
Downloads all photos from Miss Photo NSU-2010 web site (which is *really* unusable)
# -*- coding: utf-8 -*-
import urllib, sgmllib
import re
import os, shutil
class IDParser(sgmllib.SGMLParser):
'''Returns list of contestant IDs from main page'''
def __init__(self):
@andy722
andy722 / run.sh
Created February 7, 2011 21:54
Runs command in background and shows notification window on completion
#!/bin/bash
_run() {
wd=$PWD
bash -cli "$*"
result=$?
[ $result == 0 ] && description="Successfully executed" || description="Failed with code $result"
cmd=${*:-"Nothing"}
file=`mktemp`
trap "rm $file" EXIT ERR TERM KILL
@andy722
andy722 / space_hogs
Created February 7, 2011 21:57
Finds users with huge home dirs, and appends info to motd
#!/bin/bash
#
# Finds users with huge home dirs, and appends info to motd
#
#############################################################
LIMIT=5
FREE_LIMIT=
@andy722
andy722 / mounts.sh
Created February 7, 2011 22:02
Mount all shares of SMB server
#!/bin/bash
mnt_dir="/mnt"
server=$1
temp="/tmp/mnts_$$"
die() {
echo "Some error occured"
exit 1
}
@andy722
andy722 / recode.sh
Created February 7, 2011 22:03
Converting id3 tags to unicode
#!/bin/bash
for i in *; do
if [ "${i##*.}" == "mp3" ]; then
mp3unicode -s cp1251 --id3v1-encoding unicode --id3v2-encoding unicode $i
fi
done
@andy722
andy722 / swap.c
Created February 7, 2011 22:34
Various ways to swap two integer values in C
#include <stdio.h>
void swap(int *, int *);
void swap_xor(int *, int *);
int main() {
int a = 1, b = 2;
printf("a = %i, b = %i\n", a, b);
@andy722
andy722 / MatrixRotator.java
Created September 18, 2011 19:44
Rotate int matrix by 90 degrees
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class MatrixRotator {
public static void main(String[] args) throws IOException {
@andy722
andy722 / RegistrationFormActivity.java
Created October 6, 2011 17:43
WebView: file upload
/**
* New user registration.
*/
public class RegistrationFormActivity extends Activity {
// for file uploading
private final static int FILE_CHOOSER_RESULT_CODE = 1;
private ValueCallback<Uri> uploadFile;
// ...