Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'nokogiri'
require 'fileutils'
require 'date'
# usage: ruby import.rb my-blog.xml
# my-blog.xml is a file from Settings -> Basic -> Export in blogger.
data = File.read ARGV[0]
doc = Nokogiri::XML(data)
@vinodkd
vinodkd / import.rb
Last active December 17, 2015 11:19 — forked from ngauthier/import.rb
Since my posts had single and double quotes AND colons in the title, the original import.rb would fail when jekyll tried to read the yaml frontmatter. So instead of using an array and a string template, I changed the code to use a map and .to_yaml'd it. to_yaml produces the leading --- by default, so I appended the trailing one :)
require 'rubygems'
require 'nokogiri'
require 'fileutils'
require 'date'
require 'yaml'
# usage: ruby import.rb my-blog.xml
# my-blog.xml is a file from Settings -> Basic -> Export in blogger.
data = File.read ARGV[0]
@vinodkd
vinodkd / term_title.sh
Last active December 14, 2015 17:39
setting the title of terminal tabs programatically, and setting them to the current directory
# add these to your .bash_profile
# title sets your terminal tab's title to any string you pass in.
# from http://stackoverflow.com/a/1687708
function title() { echo -n -e "\033]0;$@\007";}
# cd modifies the cd command and uses title to set it to whatever the current dir is.
# from http://superuser.com/a/296555
function cd() { builtin cd "$@" && title ${PWD##*/}; }
please(show).the(square_root).of(100)
={it}([{println it}]).{clos -> [delegate[0],clos]}(square_root).{delegate[0](delegate[1](it))}(100)
=[{println it}].[delagate[0], square_root].[delegate[0](delegate[1](100))]
= [{println it}, square_root].[delegate[0](delegate[1](100))]
=println(square_root(100))
//try1
println please.class.name
println please.delegate
println show
println show.class.name
println show.delegate
println please(show).delegate
println please(show).the(square_root)
@vinodkd
vinodkd / sqr_orig.groovy
Created March 1, 2013 06:29
groovy dsl original
Object.metaClass.of = { delegate[0](delegate[1](it))}
Object.metaClass.the = { clos -> [delegate[0], clos]}
show = [ {println it} ]
square_root = { Math.sqrt(it) }
please = {it}
please show the square_root of 100
@vinodkd
vinodkd / gist:2017685
Created March 11, 2012 19:00
MaxProd.jak
public static int maxProd(int[] input){
int max1 = max2 = max3 = java.lang.Integer.MIN_VALUE;
int min1 = min2 java.lang.Integer.MAX_VALUE;
for(int i=0; i<input.length;i++){
int val= input[i];
range calcmax{
if(val > max1){
max2 = max1; // dont lose the old max1
@vinodkd
vinodkd / gist:2017661
Created March 11, 2012 18:52
MaxProd
public static int maxProd(int[] input){
int max1 = max2 = max3 = java.lang.Integer.MIN_VALUE;
int min1 = min2 java.lang.Integer.MAX_VALUE;
for(int i=0; i<input.length;i++){
// recalc the new max3 numbers
int val= input[i];
if(val > max1){
max2 = max1; // dont lose the old max1
max1=val;
@vinodkd
vinodkd / jack1.yaml
Created October 27, 2011 14:43
Yaml version of Jack AST
// yaml version of the same
- object: function
id:
comment:
fact: 'multiplies(x,y)'
name: multipliesTwo
expr:
- object: expr
id:
comment:
@vinodkd
vinodkd / JackParser.ometa
Created October 27, 2011 14:23
Basic Jack Parser in OMeta
ometa JackParser {
id = string,
comment = string,
fact = string,
name = string,
operator = name,
arg = name | expr,
header = [id:id comment:comment fact:fact] -> { id:id, comment:comment, fact:fact},