Skip to content

Instantly share code, notes, and snippets.

@roopeshvaddepally
roopeshvaddepally / gist:3888415
Created October 14, 2012 12:32
heredocs in perl and ruby
rv@v:~$ perl -e "print <<'...';
hello
world
...
"
hello
world
rv@v:~$ ruby -e "puts <<'...'
hello
world
@roopeshvaddepally
roopeshvaddepally / init.el
Created October 14, 2012 05:49
Emacs init.el custom extras
;; My setup is a emacs 24 with emacs prelude installed
(global-set-key (kbd "C-?") 'help) ;; help-command from previous versions is not there anymore
(global-set-key (kbd "C-h") 'delete-backward-char) ;; because backspace sucks
(defun other-window-backward (&optional n)
"Select Nth previous window."
(interactive "P")
(other-window (- (prefix-numeric-value n))))
import datetime
from time import mktime
def convert_date_to_datetime(date_object):
date_tuple = date_object.timetuple()
date_timestamp = mktime(date_tuple)
return datetime.datetime.fromtimestamp(date_timestamp)
def date_range(how_many=7):
for x in range(0, how_many):
@roopeshvaddepally
roopeshvaddepally / BatikService.java
Created March 20, 2012 09:33
Batik Service. Take svg, image_type as input. and convert the svg to image of given type
package ly.visual;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
@roopeshvaddepally
roopeshvaddepally / GenerateRandomString.java
Created March 15, 2012 20:18
Generate Random String of given length with alphabets
public static String generateString(int length) {
String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random rng = new Random();
char[] text = new char[length];
for (int i = 0; i < length; i++) {
text[i] = characters.charAt(rng.nextInt(characters.length()));
}
return new String(text);
}
@roopeshvaddepally
roopeshvaddepally / GetFileAsBytes.java
Created March 15, 2012 20:17
Get ByteArray of file content (don't you on large files)
public static byte[] getFileBytes(File file) throws IOException {
ByteArrayOutputStream ous = null;
InputStream ios = null;
try {
byte[] buffer = new byte[4096];
ous = new ByteArrayOutputStream();
ios = new FileInputStream(file);
int read = 0;
while ((read = ios.read(buffer)) != -1)
ous.write(buffer, 0, read);
@roopeshvaddepally
roopeshvaddepally / ReadFileAsString.java
Created March 15, 2012 20:15
Read a file as string (open(filename).read() in python)
public static String readFileAsString(String fileName) throws java.io.IOException {
java.io.InputStream is = new java.io.FileInputStream(fileName);
try {
final int bufsize = 4096;
int available = is.available();
byte data[] = new byte[available < bufsize ? bufsize : available];
int used = 0;
while (true) {
if (data.length - used < bufsize) {
byte newData[] = new byte[data.length << 1];
@roopeshvaddepally
roopeshvaddepally / _core.scss
Created March 15, 2012 20:11 — forked from hellojwilde/_core.scss
An SCSS port of the Deco Grid System (deco.gs)
/* This is an **unofficial** [SCSS](http://sass-lang.com/) port of preview 2
of the [Deco Grid System](http://deco.gs/). The Deco Grid System was
originally written by [Alexander Limi](http://limi.net/) and released under
a [public domain/BSD](http://twitter.com/limi/status/10865858377154560)
license.
This port was created by [Jonathan Wilde](http://www.speedbreeze.com/).
Jonathan doesn't deserve much credit, though, since Alexander Limi did all
of the hard work. ;) This file is licensed under the same terms as the
original Deco Grid System CSS.
@roopeshvaddepally
roopeshvaddepally / all_cron.sh
Created October 28, 2011 21:27
See cron jobs of all users
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l; done
@roopeshvaddepally
roopeshvaddepally / spec_helper.rb
Created July 19, 2011 05:23
spec helper content for spork
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'