Skip to content

Instantly share code, notes, and snippets.

@sunloverz
sunloverz / gist:4130031
Created November 22, 2012 08:42
createdocx
<?php
/**
* Generate a DOCX file
*
* @category Phpdocx
* @package create
* @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L.
* (http://www.2mdc.com)
* @license LGPL
@sunloverz
sunloverz / letsrate.js.erb
Created April 19, 2013 11:22
rate_path usage in project
$.fn.raty.defaults.path = "/assets";
$.fn.raty.defaults.half_show = true;
$(function(){
$(".star").raty({
score: function(){
return $(this).attr('data-rating')
},
number: function() {
return $(this).attr('data-star-count')
sunloverz@kg:~/projects/discourse$ vagrant box add discourse-0.8.4 ~/Downloads/discourse-0.8.4.box
Downloading or copying the box...
Extracting box...te: 27.6M/s, Estimated time remaining: 0:00:01)
Successfully added box 'discourse-0.8.4' with provider 'virtualbox'!
sunloverz@kg:~/projects/discourse$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'discourse-0.8.4'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
@sunloverz
sunloverz / gist:5991073
Created July 13, 2013 15:22
Countring the number of inversions in an array using divide and conguer algorithm
#include <iostream>
#include <string>
#include <sstream>
#include <queue>
#include <stdio.h>
#include <fstream>
using namespace std;
#define INF 19999999
long long int glob;
#include <iostream>
#include <string>
#include <sstream>
#include <queue>
#include <stdio.h>
#include <fstream>
using namespace std;
ifstream infile("IntegerArray.txt");
unsigned long long glob=0;
Problem Statement
    
Given the width and height of a rectangular grid, return the total number of rectangles (NOT counting squares) that can be found on this grid.
For example, width = 3, height = 3 (see diagram below):
__ __ __
|__|__|__|
|__|__|__|
|__|__|__|
In this grid, there are 4 2x3 rectangles, 6 1x3 rectangles and 12 1x2 rectangles. Thus there is a total of 4 + 6 + 12 = 22 rectangles. Note we don't count 1x1, 2x2 and 3x3 rectangles because they are squares.
@sunloverz
sunloverz / deploy.rb
Created October 24, 2013 09:29 — forked from bkutil/deploy.rb
after "deploy:symlink", "deploy:restart_workers"
after "deploy:restart_workers", "deploy:restart_scheduler"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
@sunloverz
sunloverz / fifteen_puzzle
Last active August 20, 2020 12:47
fifteen puzzle game
#include <iostream>
#include <iterator>
#include <functional>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <sstream>
#include <string>
@sunloverz
sunloverz / ruby-metaprogramming
Created March 16, 2014 14:33
Ruby metaprogramming list of spells (ie design patterns)
Argument Array
Collapse a list of arguments into an array.
Around Alias
Call the previous, aliased version of a method from a redefined method.
Blank Slate
Remove methods from an object to turn them into Ghost Methods.
Class Extension
curl -H "Content-Typ"Authorization: OAuth O7KrMTwmw997iq0KzL7v" -d '{"messages":[{"body":"hello world!"}]}' "http://158.181.176.161:8080/3/projects/53a3b3bd5e8edd1245000005/queues/my_queue/messages"