Skip to content

Instantly share code, notes, and snippets.

#include <iostream> // For std::cout, std::flush, and std::endl
#include <chrono> // For std::chrono::milliseconds
#include <thread> // For std::this_thread::sleep_for
/** Update current line without putting the text on the next line
*
* This is done by using \r (carriage return) instead of \n
*/
int main(const int argc, char const* argv[]) {
@NigoroJr
NigoroJr / coin_change.cpp
Last active August 29, 2015 14:22
Get the number of combinations to make the target number from a given set of denominations
#include <assert.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using MemoizationTable = std::vector<std::vector<int>>;
/** Utility function to dump the memoization table
*/
@NigoroJr
NigoroJr / xpath.rb
Last active August 29, 2015 14:22
Sample program for using xpath with nokogiri
#!/usr/bin/env ruby
require 'robotex'
require 'nokogiri'
require 'open-uri'
url = 'http://www.cplusplus.com/reference/ios/basic_ios/'
# Fake User Agent
ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1'
@NigoroJr
NigoroJr / Gemfile
Last active August 29, 2015 14:22
Simple web scraper
source 'https://rubygems.org'
gem 'robotex'
gem 'nokogiri'
gem 'trollop'
gem 'thread'
@NigoroJr
NigoroJr / sort_du.rb
Created June 9, 2015 01:35
Simple script that sorts the output from du
#!/usr/bin/env ruby
# A program that sorts the output from the command `du -h'
# Use it like: du -h . | $PROGRAM_NAME [-r|--reverse]
SUFFIX = {
'K' => 1E3,
'M' => 1E6,
'G' => 1E9,
'T' => 1E12,
@NigoroJr
NigoroJr / active_record_sample.rb
Created June 19, 2015 00:42
Stupid sample script for ActiveRecord
#!/usr/bin/env ruby
require 'sqlite3'
require 'active_record'
ActiveRecord::Base.establish_connection(
adapter: 'sqlite3',
database: 'sample.db'
)
#include <iostream>
class Foo {
public:
Foo() {}
Foo(const int x) : x(x) {}
int other_x(const Foo& other) {
// Accessing private member variable
return other.x;
#!/usr/bin/env ruby
require 'fileutils'
require 'slop'
# Move image files downloaded using Pixiv Downloader to appropriate
# directories.
#
# https://chrome.google.com/webstore/detail/pixiv-downloader/lkpfhmlbjibbcinophhcbmapjbhboodd
#
#!/usr/bin/env ruby
def measure
`uptime`.split(' ')[-3].chop.to_f
end
max = -1
maxes = []
loop do
#include <iostream>
#include <queue>
struct Foo {
Foo(const int x) : x(x) {}
int x;
};
std::ostream& operator<<(std::ostream& os, const Foo& f) {
os << f.x;