Skip to content

Instantly share code, notes, and snippets.

View antsmartian's full-sized avatar
💭
Hacking...

antsmartian antsmartian

💭
Hacking...
  • India
View GitHub Profile
@antsmartian
antsmartian / Histogram.c
Created April 5, 2012 08:44
Count the word lengths in a file :)
#include <stdio.h>
#define INSIDEWORD 1
#define OUTSIDEWORD 0
#define MAXWORD 10
main() {
char c;
int i=0,j,state= OUTSIDEWORD,words =0, ndigits[10],length=0;
for(i=0;i<10;i++)
ndigits[i] = 0;
while((c = getchar()) != EOF)
@antsmartian
antsmartian / chicken.groovy
Created April 6, 2012 12:54
Description of Chicken in a Programming Language.
String.metaClass.nutritions = {
def pro = [Carbohydrates:0.0,Protein:24.68,Fat:12.56,
Water:63.93]
if(delegate.toLowerCase() == "chicken")
{
println "--------$delegate Properties is--------"
pro.each { k,v ->
print k + " found in chicken is "
println v
@antsmartian
antsmartian / version2.groovy
Created April 8, 2012 17:09
Web Scraping using Groovy and Jsoup!
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
println "WebScraping with Groovy \n"
def url = "http://rates.goldenchennai.com/";
def url2 = "http://scores.sify.com/index.shtml"
def document = Jsoup.connect(url).get();
def cricDocument = Jsoup.connect(url2).get()
def goldDetails = document.select(".yellowTxt")
@antsmartian
antsmartian / tree.md
Created April 24, 2012 10:07 — forked from timyates/tree.md
A two-line tree in Groovy

Two line Tree in Groovy

The other day, I saw Harold Cooper's One-line tree in Python via autovivication, and wondered if the same thing was possible in Groovy.

The answer is yes! But you need to define the variable tree before you can assign it to the self-referential withDefault closure, hence with Groovy, it's a two-line solution ;-)

Anyway, given:

def tree
@antsmartian
antsmartian / tree.md
Created April 24, 2012 12:03 — forked from kiy0taka/tree.md
A one-line tree in Groovy

One line Tree in Groovy

The other day, I saw Harold Cooper's One-line tree in Python via autovivication, and wondered if the same thing was possible in Groovy.

The answer is yes! But you need to define the variable tree before you can assign it to the self-referential withDefault closure, hence with Groovy, it's a two-line solution ;-)

Anyway, given:

def tree = { [:].withDefault{ owner.call() } }
@antsmartian
antsmartian / occ.groovy
Created June 17, 2012 16:11
Problem from TopCoder (500 Points).
def input = "92"
def digit1 = 1
def count1 = 1
def digit2 = 0
def count2 = 0
def temp = input as long
if(count1 >= 1 || count2 >= 1)
{
@antsmartian
antsmartian / keystoreOpen.groovy
Created July 3, 2012 12:01
Code to work with KeyStore (Open a Keystore)
char[] passwords = "*******"
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream f = new FileInputStream(<!`path to keyStore File~!>)
keyStore.load( f , passwords );
@antsmartian
antsmartian / powerN.groovy
Created July 7, 2012 04:45
Calculating power of N using Divide and Conquer Technique
//running in O(log n) time
​def powerN(BigInteger accum,BigInteger x,def n)
{
if(n == 1)
return accum
else
return powerN(accum = accum*x,x,n-1)
}
@antsmartian
antsmartian / Setup.sh
Created July 12, 2012 08:16
Shell script for auditing in Linux
#!/bin/bash
sudo apt-get install auditd
sudo auditd
#Setting up system parameters
sudo auditctl -b 1000
sudo auditctl -f 1
sudo auditctl -r 5
sudo auditctl -e 1
@antsmartian
antsmartian / Sync.sh
Created July 14, 2012 11:36
Shell script for syn with ntp servers for proper time.
#!/bin/bash
#Call the config file . .
source configFile.sh
#Install ntp on the server
sudo apt-get install ntp
#The config files for ntp lies in /etc/ntp.conf.
#We are changing the Servers time to our nearest geo location.