Skip to content

Instantly share code, notes, and snippets.

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

antsmartian antsmartian

💭
Hacking...
  • India
View GitHub Profile
@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/
*/
@sente
sente / formatXML.js
Last active April 4, 2024 12:20
javascript to format/pretty-print XML
The MIT License (MIT)
Copyright (c) 2016 Stuart Powers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@coolaj86
coolaj86 / how-to-publish-to-npm.md
Last active April 2, 2024 20:18
How to publish packages to NPM

Getting Started with NPM (as a developer)

As easy as 1, 2, 3!

Updated:

  • Aug, 08, 2022 update config docs for npm 8+
  • Jul 27, 2021 add private scopes
  • Jul 22, 2021 add dist tags
  • Jun 20, 2021 update for --access=public
  • Sep 07, 2020 update docs for npm version
@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
@kiy0taka
kiy0taka / tree.md
Created April 24, 2012 09:56 — forked from timyates/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 / 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
@fcingolani
fcingolani / index.html
Created August 9, 2012 02:16
How to render a full PDF using Mozilla's pdf.js
<html>
<body>
<!-- really dirty! this is just a test drive ;) -->
<script type="text/javascript" src="https://raw.github.com/mozilla/pdf.js/gh-pages/build/pdf.js"></script>
<script type="text/javascript">
function renderPDF(url, canvasContainer, options) {
var options = options || { scale: 1 };
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active May 2, 2024 05:55
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@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);
@juanqui
juanqui / gist:7564275
Created November 20, 2013 14:41
Golang Kqueue Snippet
// helpful links:
// https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/EV_SET.2.html
// http://julipedia.meroh.net/2004/10/example-of-kqueue.html
// create kqueue
kq, err := syscall.Kqueue()
if err != nil {
log.Println("Error creating Kqueue descriptor!")
return
}