One-liner search and replace
1 |
katy:~ mm$ perl -pi.bak -e "s/search/replace/g" file.sql |
1 |
katy:~ mm$ perl -pi.bak -e "s/search/replace/g" file.sql |
Today I got a new macbook and I ran into a problem because the subversion installed on the laptop was too new for our subversion system.
Error message:
1 |
svn: E155036: Working copy '/Users/mm/some/repository' is too old (format 10, created by Subversion 1.6) |
So I had install an older version of subversion, here is how I did it.
Tap homebrew versions.
1 2 3 4 5 6 7 8 9 10 |
katy:~ mm$ brew tap homebrew/versions Cloning into '/usr/local/Library/Taps/homebrew-versions'... remote: Reusing existing pack: 1654, done. remote: Counting objects: 7, done. remote: Compressing objects: 100% (7/7), done. remote: Total 1661 (delta 4), reused 0 (delta 0) Receiving objects: 100% (1661/1661), 544.38 KiB | 457.00 KiB/s, done. Resolving deltas: 100% (864/864), done. Checking connectivity... done Tapped 130 formula |
Install subversion16
1 |
katy:~ mm$ brew install subversion16 |
Enjoy!
First login as root – Clean login – sudo will not work if you’re changing a UID on an already logged in user.
Find the user’s old UID:
1 |
id user1 |
uid=1000(user1) ….
Change the UID:
1 |
usermod -u 1001 user1 |
Update files and directories owned by the user to the new UID:
1 |
find / -uid 1000 -exec chown -h 1001 '{}' \+ |
Reboot and the UID has been changed.
Powershell commands:
1 2 3 4 5 6 7 8 9 10 11 |
# View registry settings Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0 # Change registry settings # Reverse mouse wheel scroll FlipFlopWheel = 1 # Normal mouse wheel scroll FlipFlopWheel = 0 Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0 | ForEach-Object { Set-ItemProperty $_.PSPath FlipFlopWheel 1 } # The command for normal (non-inverted) scrolling has the `0` and `1` swapped: # Restore default scroll direction Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 1 | ForEach-Object { Set-ItemProperty $_.PSPath FlipFlopWheel 0 } |
Switching around from Windows and Mac OS x can be a bit confusing, so I decided to reverse the scroll direction on my Windows machines, so they would feel the same as under Mac OS x.
Here is how I did it:
Source: http://www.vvse.com/blog/blog/2012/02/27/reverse-scrolling-on-windows-7/
Tested on nginx 1.4 and nginx 1.2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
server { listen 80; server_name hostname; error_log /var/www/flow/logs/error.log debug; access_log /var/www/flow/logs/access.log combined; root /var/www/flow/Web; index index.html index.php; location ~ ^/_Resources/Persistent/ { rewrite "^/(_Resources/Persistent/.{40})/.+(\..+)" /$1$2 break; } location ~ ^/_Resources/ { access_log off; log_not_found off; expires max; break; } location ~* /favicon.ico { access_log off; log_not_found off; break; } location ~* /\.ht { deny all; access_log off; log_not_found off; break; } location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; include /etc/nginx/fastcgi_params; fastcgi_index index.php; fastcgi_param FLOW_CONTEXT Development; fastcgi_param FLOW_REWRITEURLS 1; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_read_timeout 30m; } } |
One of the drawbacks of Hyper-V on Windows 8 Pro, is that lack of NAT. Luckily Windows 8’s networking supports port proxies in netsh.
1 2 3 4 |
Host ip = 192.168.1.25 Guest ip = 192.168.137.147 netsh interface portproxy add v4tov4 listenport=22 listenaddress=192.168.1.25 connectport=22 connectaddress=192.168.137.147 |
Source: http://technet.microsoft.com/en-us/library/cc776297(v=ws.10).aspx
While moving virtual machines around, it will usually mean a change on MAC addresses on the networking interfaces, which will create new eth nodes on the machine.
Reasons for the renaming of eth nodes on the machine, is due to the persistent mapping on Linux systems using udev.
Fixing this is done by removing the entities in the /etc/udev/rules.d/70-persistent-net.rules and reboot the machine.
Simple wake-on-lan script, to wake up a WoL enabled computer when it receives a connection. This script is currently running on an old router.
It requires the wol command.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
#!/usr/bin/php -q <?php if (!function_exists('pcntl_fork')) die('PCNTL functions not available on this PHP installation'); declare(ticks=1); //Configuration! $addressBind = '192.168.1.5'; $portBind = 10066; $wolEnabledIP = '192.168.1.3'; $wolEnabledNetwork = '192.168.1.255'; $wolEnabledMAC = '00:12:34:56:78:90'; //End-Configuration! $pid = pcntl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { exit; } else { //we are the child } if (posix_setsid() == -1) { die("could not detach from terminal"); } //Write pid $posid=posix_getpid(); $fp = fopen("/var/run/wol-daemon.pid", "w"); fwrite($fp, $posid); fclose($fp); //Signal handlers pcntl_signal(SIGTERM, "sig_handler"); pcntl_signal(SIGHUP, "sig_handler"); function sig_handler($signo) { switch ($signo) { case SIGTERM: exit; break; } } /* Allow the script to hang around waiting for connections. */ set_time_limit(0); //Turn on implicit output flushing so we see what we're getting as it comes in. ob_implicit_flush(); if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n"; } if (socket_bind($sock, $addressBind, $portBind) === false) { echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; } if (socket_listen($sock, 5) === false) { echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; } do { if (($msgsock = socket_accept($sock)) === false) { echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; break; } $fp = @fsockopen($wolEnabledIP, 139, $errno, $errstr, 1); //The WoL enabled computer is running Windows, that's why we are testing on port 139. if (!$fp) { $msg = "\nSince Celina is not up, I will try to wake her up for you\nPlease wait...\n"; socket_write($msgsock, $msg, strlen($msg)); pclose(popen("wol -i '.$wolEnabledNetwork.' -p 7 ".$wolEnabledMAC, "r")); while(true) { sleep(1); $fpC = @fsockopen($wolEnabledIP, 139, $errno, $errstr, 1); if (!$fpC) { continue; } else { $msg = "Celina is up and spinning, feel free get the hell out! ;-)\n"; socket_write($msgsock, $msg, strlen($msg)); break; } } } else { $msg = "\nCelina is up, so what is your point?\n"; socket_write($msgsock, $msg, strlen($msg)); fclose($fp); } socket_write($msgsock, $msg, strlen($msg)); socket_close($msgsock); } while (true); socket_close($sock); |
Source: AutoScale on BitBucket
General idea:
Use a locale memcached database to keep an eye on load for the current server, using data from processes using resources on the node. (Eg. not connection time to database server, only pure processing power used on current node).
Usage:
Edit config.php.
execute agent.php
Todo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
/** <ul> <li>Terminal constructor</li> </ul> **/ function Terminal() { /** * Global variables **/ this.termDiv = null; this.promptDiv = null; this.prompt = null; this.user = null; this.company = null; this.cwd = null; this.debug = false; this.dispatch = new Array(); this.container = document.getElementById("container"); this.lines = 16; this.currentCmd = null; } /** <ul> <li>Terminal init function</li> </ul> **/ Terminal.prototype.init = function(divTerm) { // Set divTerm if (document.getElementById(divTerm) != undefined && this.termDiv == null) { this.termDiv = document.getElementById(divTerm); } else { return; } // Init prompt this.promptFunc(); // Set height on container this.container.style.height = 16*this.lines*1.5 + 'px'; } Terminal.prototype.promptFunc = function() { /** * Write prompt if it does not exists **/ if ((document.getElementById("promptDiv") == undefined || document.getElementById("promptDiv") == null) && this.promptDiv == null) { // Create promptDiv element var promptElement = document.createElement('div'); promptElement.setAttribute('id', 'promptDiv'); promptElement.innerHTML = '<span id="cd">' + this.user + '@' + this.company + ':' + this.cwd + '$</span> <input type="text" id="prompt" />'; // Write after this.termDiv this.termDiv.parentNode.insertBefore(promptElement, this.termDiv.nextSibling); this.promptDiv = document.getElementById("promptDiv"); this.prompt = document.getElementById("prompt"); this.prompt.style.width = this.termDiv.offsetWidth - document.getElementById("cd").offsetWidth - 20 + 'px'; } else { return; } // Put focus on the promt this.prompt.focus(); this.prompt.onkeydown = function (e) { if (Terminal.debug == true) { console.log(e) }; if (e == undefined) { e = window.event; } var keyCode = e.keyCode; switch (keyCode) { /** * Tab completion **/ case 9: if (Terminal.currentCmd == null) { } else { } break; /** * Enter **/ case 13: Terminal.addContent(Terminal.user + '@' + Terminal.company + ':' + Terminal.cwd + '$ ' + Terminal.prompt.value); Terminal.promptHide(); Terminal.processInput(Terminal.prompt.value); break; default: this.tabCount = 0; break; } } } Terminal.prototype.promptShow = function() { this.prompt.value = ''; this.promptDiv.style.visibility = 'visible'; this.prompt.focus(); this.prompt.style.width = Terminal.termDiv.offsetWidth - document.getElementById("cd").offsetWidth - 20 + 'px'; } Terminal.prototype.promptHide = function() { this.promptDiv.style.visibility = 'hidden'; } Terminal.prototype.addContent = function(data) { var newLine = document.createElement('p'); newLine.innerHTML = data; this.termDiv.appendChild(newLine); this.container.scrollTop = this.container.scrollHeight; } Terminal.prototype.processInput = function(input) { var _cmd = input.split(' ')[0]; if(this.dispatch[_cmd] == undefined) { this.addContent(_cmd + ": command not found"); this.promptShow(); } else { var _result = this.dispatch[_cmd](input); if (_result != true) { this.addContent(_result); } this.promptShow(); } } Terminal.prototype.registerCommand = function(command, dispatch_method) { try { if( typeof dispatch_method === 'function' || typeof dispatch_method === 'string' || typeof dispatch_method === 'object' ) { this.dispatch[command] = dispatch_method; } else { throw 'Dispatch needs to be a method'; } } catch ( e ) { // Error Handling here } } function lsCmd(data) { } function cdCmd(data) { } cdCmd.prototype.autocomplete = function(data) { } |
Usage:
1 2 3 4 5 6 7 8 9 10 11 |
<div id="container"> <div id="terminal"></div> </div> <script type="text/javascript"> var Terminal = new Terminal(); Terminal.debug = true; Terminal.user = 'mm'; Terminal.company = 'lessthinking'; Terminal.cwd = '~/Projects'; Terminal.init("terminal"); </script> |
Reply