Skip to content

Instantly share code, notes, and snippets.

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

antsmartian antsmartian

💭
Hacking...
  • India
View GitHub Profile
@ralt
ralt / gist:d1e07c3c77813383734b
Last active August 29, 2015 14:02
cpp preprocessor for JS source
/*
$ cpp -P -nostdinc test.js bundle.js
# OR
$ cpp -P -nostdinc test.js
# To give parameters, use -D, like this:
$ cpp -P -nostdinc -D DEV test.js
@melix
melix / fatfingers.groovy
Last active August 29, 2015 14:06
Fat fingers correction in Groovy
import org.codehaus.groovy.reflection.ClassInfo
import org.codehaus.groovy.runtime.MethodRankHelper
trait FatFingers {
def methodMissing(String name, args) {
def ci = ClassInfo.getClassInfo(this.class)
def methods = [*ci.metaClass.methods,*ci.metaClass.metaMethods]
def sugg = MethodRankHelper.rankMethods(name,args,methods)
if (sugg) {
sugg[0].invoke(this, args)
@melix
melix / Fibonenchmark
Last active August 29, 2015 14:10
Fibonacci Benchmark
# Run complete. Total time: 00:34:14
Benchmark Mode Samples Score Error Units
o.g.m.f.FibonacciMicroBenchmark.groovy_primitive_cs avgt 30 1.961 ± 0.055 ms/op
o.g.m.f.FibonacciMicroBenchmark.baseline_java_30 avgt 30 2.004 ± 0.084 ms/op
o.g.m.f.FibonacciMicroBenchmark.baseline_java_boxing_30 avgt 30 5.504 ± 0.036 ms/op
o.g.m.f.FibonacciMicroBenchmark.groovy_primitive_30 avgt 30 5.733 ± 0.024 ms/op
o.g.m.f.FibonacciMicroBenchmark.groovy_indy_30 avgt 30 5.903 ± 0.033 ms/op
o.g.m.f.FibonacciMicroBenchmark.golo_30 avgt 30 6.545 ± 0.060 ms/op
o.g.m.f.FibonacciMicroBenchmark.nashorn_30 avgt 30 7.812 ± 0.061 ms/op
anonymous
anonymous / nytimesscraper.java
Created December 18, 2014 08:31
NY Times Top Books - hacked together, sorry
import java.util.List;
import org.apache.commons.lang3.text.WordUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class NytimesScraper {
public static void getBooks(){
@antsmartian
antsmartian / #King_Of_Kings.groovy
Created January 15, 2012 06:11
Problem solved on Top Coders.(14.2.500)
//map for managing the conversion from roman to no's
def map =[I:1,II:2,III:3,IV:4,V:5,VI:6,VII:7,VIII:8,IX:9,X:10,XI:11]
//map for managing the conversion from no to romans
def map1 = ['1':"I",'2':"II",'3':"III",'4':"IV",'5':"V",'6':"VI",'7':"VII",'8':"VIII",'9':"IX",'10':"X",'11':"XI"]
//temp variables
ans = []
res = []
//final result
res1 = []
//for managing the flow of algorithm
@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
@danveloper
danveloper / MemoizedLambdaFib.java
Last active December 16, 2015 08:19
Memoized Fibonacci calculation using lambdas in Java 8
public class MemoizedLambdaFib {
interface MemoizedFunction<T, R> {
enum Cache {
_;
Map<Object, Object> vals = new HashMap<>();
}
R calc(T t);
import React, { Component, createContext } from 'react'
function initStore(store) {
const Context = createContext();
class Provider extends React.Component {
constructor() {
super();
this.state = store.initialState;
}
@cjohansen
cjohansen / gist:739589
Created December 13, 2010 20:55
Showing how to fake server requests with Sinon.JS and Jasmine
/*
Load Sinon.JS in the SpecRunner:
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.0.1/jasmine-html.js"></script>
<script type="text/javascript" src="sinon-1.0.0.js"></script>
<script type="text/javascript" src="sinon-ie-1.0.0.js"></script>
http://cjohansen.no/sinon/
*/
@antsmartian
antsmartian / LEARNING.md
Last active May 11, 2019 20:30
Learning Postgres

Hello all, I'm in the process of learning Postgres and I find it very hard to find a resource where postgres is explained in terms of developer. Since I'm in the process of reading and applying it in my side project; I treat this gist as my knowledge sharing place on Postgres and its features. Each sub-heading tries to explain the concepts of Postgres with simple example. I may be wrong at times here, if so please free to comment.

All the codes are written and run on psql

I would be adding many stuffs as I learn them. There is no particular order in which I add the contents.

I'm using the following postgres version:

SELECT version();