Skip to content

Instantly share code, notes, and snippets.

@mub
mub / proxyAutoConfig-PAC.js
Created November 19, 2012 03:30
Browsers trail
/*
Proxy Auto-Config file, see http://en.wikipedia.org/wiki/Proxy_auto-config
This would work with most browsers and more, do not need any heavy plugins with this script and it's more powerful, flexible and maintainable than
any of plugins. Instead of clicking through menus, just point to this file anywhere in your FS.
*/
function FindProxyForURL(url, host) {
/* example with using regex:
var regexpr = /[a-zA-Z]{4}.microsoft.com/;
if(regexpr.test(host)) { ...
*/
@mub
mub / RMI_RPC.rb
Last active October 12, 2015 17:38
Ruby Trail
#Remote Method Invocation (Remote Procedure Call) in Ruby.
# Four files rolled in one
# dRbUrl.rb BEGIN
require 'drb/drb'
module DrbTry
URL = 'druby://localhost:8787'
end
@mub
mub / ExcelExportChart.vba
Created November 7, 2012 08:28
Visual Basic For Applications Trail
Sub Export_Macro()
Dim sChartName As String
Dim sPrompt As String
Dim sDefault As String
If ActiveSheet Is Nothing Then GoTo ExitSub
If ActiveChart Is Nothing Then GoTo ExitSub
sPrompt = "Chart will be exported into directory of active workbook."
sPrompt = sPrompt & vbNewLine & vbNewLine
@mub
mub / columnChart.mxml
Created November 6, 2012 09:49
Flex trail
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white" viewSourceURL="srcview/index.html">
<mx:Style>
@namespace mx "library://ns.adobe.com/flex/mx";
/*mx|ColumnChart {
@mub
mub / git-mv.sh
Created November 5, 2012 21:55
Git Trail
#!/usr/bin/zsh
# rename a file from a subdirectory on the Git path.
NAME_FROM="$1"
NAME_TO="$2"
[[ -z $NAME_FROM || -z $NAME_TO ]] && { echo "Need name from and name to"; return 1 }
[[ -f $NAME_FROM ]] || { echo "$NAME_FROM is not a file"; return 2 }
[[ -f $NAME_TO ]] && { echo "File $NAME_TO exists"; return 3 }
function findgitroot {
local ORIG_DIR; ORIG_DIR=$PWD
GIT_ROOT=''
@mub
mub / ubuntuToDev-12.10.sh
Created November 1, 2012 07:12
Ubuntu 12.10 tuning up for development
# This is a collection of shell snippets I used to tune up the Ubuntu 12.10 distribution to a development workstation without multimedia to run in a virt.
# Most of those commands were ran as root, see the first 2 comments under this code about getting to the root prompt in Ubuntu.
# now let's start with fresh Ubuntu install.
# toss out all this stuff, games, thunderbird (got Outlook on the Windows 7 host), samba (using VMWare's shared folders instead),
# pidgin (Using Lync on the host) etc, anything that eats up the space and clutters menus without giving me any leverage:
apt-get remove --purge --ignore-missing gbrainy aisleriot gbrainy gnome-games-* gnome-sudoku gnomine libgme0 mahjongg bogofilter* empathy* thunderbird* \
remmina gwibber* tomboy avahi-daemon transmission-* whoopsie samba* modemmanager ubuntuone* rhythmbox* activity-log-manager-common python-zeitgeist \
zeitgeist-core deja-dup pidgin* apport*
@mub
mub / CamelizeVariablize.rb
Created September 10, 2012 18:31
Ruby features trail
# To make foreign identifiers look more Java-ish way
# similar methods are in Rails, but if you don't want to drag the whole Rails around - can just include this.
class String # easier to copy it from Rails than dragging the Rails over
def camelize
return self.downcase.capitalize if self =~ /[A-Z]+/ && self !~ /_/
return self.capitalize if self !~ /_/
split('_').map { |e| e.capitalize }.join
end
def variablize
@mub
mub / defineOverloadWithVarArgs.c
Created September 4, 2012 18:06
C language/platforms feature trail
/* How to overload a define with different count of args in C or disable it altogether
build with:
gcc -D SAY_IT=1 testMultiDef.c -o testMultiDef.exe
depending on the SAY_IT value the SAY calls in the code will either talk or keep mum
*/
#if defined(SAY_IT) && SAY_IT
// important to provide enough _1, _2 ... _N to provide the N args max
#define _N_SAY(_1, _2, _3, _4, NAME, ...) NAME
#define SAY(...) _N_SAY(__VA_ARGS__, SAY4, SAY3, SAY2, SAY1)(__VA_ARGS__)
@mub
mub / apacheAvroDownload.sh
Created September 3, 2012 09:51
Linux shell scripting trail
cat javaList.txt | xargs -n 1 -I {} wget http://mirror.metrocast.net/apache/avro/avro-1.7.2/java/{} -O {}
cat javaList.txt | grep .asc | xargs -n 1 -I {} gpg -verify -v {}
@mub
mub / countBitsByCondensingAndKB.cpp
Created August 19, 2012 05:33
Bit count and reversal different ways, C++
#include <iostream>
#include <sstream>
#include <iomanip>
using namespace std;
static const int POW_OF_2[] = {1, 2, 4, 8, 16};
static const int COUNT_MASKS[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};
unsigned int countByKernighanBrian(unsigned int src) {