This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
def writeBytes(size,fileName): | |
start = time.time() | |
cmd = "dd if=/dev/zero of=" + fileName + " bs=" + size + " count=1 status=noxfer > /dev/null" | |
print cmd | |
os.system(cmd) | |
return time.time() - start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns number starting from offset up to n-1 | |
*/ | |
function getRandomWithOffset(n,offset) { | |
return Math.floor(Math.random()*n+offset); | |
} | |
/** | |
* Returns random integer from 0 to n-1 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
import java.util.regex.*; | |
import java.net.*; | |
final public class NewsCrawler implements Runnable { | |
private static int NEWS_PORT = 119; | |
private static String _newsServer = new String("news.telcel.net.ve"); | |
private static String COMMAND_HEAD = new String("head"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Console PHP Script to process thousands of Wordpress posts. | |
* | |
* You can use this script as an example on how to: | |
* > extract urls and put them in the posts metadata. | |
* > download images referenced by the HTML out on flickr into the post | |
* > massaging the post HTML | |
* | |
* The script makes use of the wordpress api, in order to do this it turns off the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#let's say you receive several variables and you want none of them to have trailing slashes | |
backup_name='mysql/' | |
backup_source_path='/var/lib/mysql/' | |
backup_destination_path='/mnt/nas/mysql_backups/' | |
#you can put them in a tuple and use list comprehension to operate on all of them | |
#and reassign them | |
(backup_name, backup_source_path, backup_destination_path) = [ x.rstrip('/') for x in (backup_name, backup_source_path, backup_destination_path)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#first find the files that need to be changed, and output their paths to a text file | |
#I use 'cut', to trim the ":" left by the grep output. | |
grep "FrostWire(TM)" * -R | awk {'print $1'} | cut -d ":" -f 1 > tm_replace | |
#then go through each file path in the text file and perform a search and replace using perl regex | |
for FILE in `cat tm_replace`; do perl -p -i -e 's/FrostWire\(TM\)/FrostWire\(R\)/g' $FILE; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
public class Solution { | |
public static List<List<Integer>> getDirtyPositions(String[] board) { | |
List<List<Integer>> dirtyPositions = new ArrayList<List<Integer>>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function selectText(element) { | |
var doc = document | |
, text = doc.getElementById(element) | |
, range, selection | |
; | |
if (doc.body.createTextRange) { //ms | |
range = doc.body.createTextRange(); | |
range.moveToElementText(text); | |
range.select(); | |
} else if (window.getSelection) { //all others |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Comparator; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Map.Entry; | |
import java.util.Set; | |
public class HistoHashMap<K> { | |
private final Map<K,Integer> map = new HashMap<K, Integer>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dpkg-parsechangelog -lchangelog |
OlderNewer