Skip to content

Instantly share code, notes, and snippets.

@szydan
szydan / memcached-flush
Created August 16, 2012 09:58
Flush memcached in one line
echo -e "flush_all\nquit\n" | telnet localhost 11211
@szydan
szydan / create-file
Created August 16, 2012 10:01
Create a file of certain size filed with random content or zeros
#how to create a file of certain size and random content
dd if=/dev/urandom of=output.dat bs=1024 count=1024
#the same for zero’ish content
dd if=/dev/zero of=output.dat bs=1024 count=1024
@szydan
szydan / pom.xml
Last active October 9, 2015 15:07
Convert java Object to class instance using jackson
// where data is Object
ObjectMapper mapper = new ObjectMapper();
MyClass myClass = mapper.readValue(mapper.writeValueAsString(data), ConsoleEvent.class);
// then to convert the object to json
mapper.writeValue(System.out, myClass);
// with pretty printng
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
@szydan
szydan / gist:3859607
Created October 9, 2012 15:41
How to limit internet connection speed on linux or mac
sudo ipfw pipe 1 config bw 350kbit/s plr 0.05 delay 500ms
sudo ipfw add pipe 1 dst-port http
#to reset to your initial settings:
sudo ipfw flush
@szydan
szydan / gist:3859983
Created October 9, 2012 16:48
Install webapp on few servers at once
for h in root@apps0{1,2}; do scp app.war $h:/var/lib/tomcat6/. && ssh $h 'cd /var/lib/tomcat6 && mv app.war webapps/. && echo Upgraded on $(hostname)'; done
@szydan
szydan / gist:3871561
Created October 11, 2012 10:41
how to copy file from hdfs to local disk without hadoop installation
/*
* Copy file from hdfs to local disk without hadoop installation
*
* params are something like
* hdfs://node01.sindice.net:8020 /user/bob/file.zip file.zip
*
* Credits for Josef Niedermeier
*
*/
@szydan
szydan / promises.md
Created October 15, 2012 08:32 — forked from domenic/promises.md
You're Missing the Point of Promises

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
    // the rest of your code goes here.
});
@szydan
szydan / gist:3939113
Created October 23, 2012 14:37
search for string in bunch of files
// here searching for .when( string inside my workspaces
find ~/workspace*/ -iname "*.js" -exec grep --color -lI "\.when(" '{}' \;
@szydan
szydan / gist:3946251
Created October 24, 2012 14:09
Avoiding the Reference Problem inside loops
// borrowed from jsvascript garden
// http://bonsaiden.github.com/JavaScript-Garden/#function.closures
// In order to copy the value of the loop's index variable, it is best to use an anonymous wrapper
for(var i = 0; i < 10; i++) {
(function(e) {
setTimeout(function() {
console.log(e);
}, 1000);
})(i);
@szydan
szydan / gist:4017536
Created November 5, 2012 14:49
how to conditionally ignore junit test
@Test
public void testAdd() {
Assume.assumeTrue(someCondition());
// eg Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
...
}