Skip to content

Instantly share code, notes, and snippets.

View hgupta's full-sized avatar

Harsh Gupta hgupta

View GitHub Profile
@hgupta
hgupta / TrueColour.md
Created September 24, 2018 02:57 — forked from XVilka/TrueColour.md
True Colour (16 million colours) support in various terminal applications and terminals

Colours in terminal

It's a common confusion about terminal colours... Actually we have this:

  • plain ascii
  • ansi escape codes (16 colour codes with bold/italic and background)
  • 256 colour palette (216 colours + 16 ansi + 24 gray) (colors are 24bit)
  • 24bit true colour ("888" colours (aka 16 milion))
printf "\x1b[${bg};2;${red};${green};${blue}m\n"
@hgupta
hgupta / gevent_task_queue.py
Created April 22, 2018 17:40 — forked from ls0f/gevent_task_queue.py
a simple gevent task queue
#coding:utf-8
from gevent import monkey
monkey.patch_all()
import logging
import gevent
logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger("GeventTaskQueue")
from gevent.queue import Queue, Empty
# http://wiki.apache.org/solr/FAQ#How_can_I_delete_all_documents_from_my_index.3F
# http://wiki.apache.org/solr/UpdateXmlMessages#Updating_a_Data_Record_via_curl

curl "http://index.websolr.com/solr/a0b1c2d3/update?commit=true" -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'

I'm amused at the traction this little gist is getting on Google! I would be remiss not to point out that six+ years later I'm still helping thousands of companies on a daily basis with their search index management, by providing managed Solr as a service over at Websolr, and hosted Elasticsearch at Bonsai. Check us out if you'd like an expert helping hand at Solr and Elasticsearch hosting, ops and support!

@hgupta
hgupta / inverse_fizzbuzz.rb
Last active August 29, 2015 14:25 — forked from s-yano/inverse_fizzbuzz.rb
Inverse FizzBuzz
def fizzbuzz(x)
x%3==0 && x%5==0 ? "fizzbuzz" : x%3==0 ? "fizz" : x%5==0 ? "buzz" : nil
end
def accept?(a, n)
return n if a.empty?
case fizzbuzz(n)
when nil
accept?(a, n+1)
when a.first
<tr>
<td><%=@key.split(".").drop(1) %></td>
<td><%= @value%></td>
</tr>
@hgupta
hgupta / varbinary_migration_columns_initializer.rb
Last active August 29, 2015 14:02
Adding MySQL data type like varbinary support for Rails Migrations
# Provide varbinary columns in a Migration.
# Probably a better way to do this?
#
# Usage:
# => t.varbinary :column, :limit => 20, ....[options]
#
ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
def type_to_sql_with_varbinary(type, limit = nil, precision = nil, scale = nil)
return type_to_sql_without_varbinary(type, limit, precision, scale) unless :varbinary == type.to_sym
require 'active_record'
require 'minitest/autorun'
require 'logger'
puts "ActiveRecord: #{ActiveRecord::VERSION::STRING}"
case ARGV[0]
when 'pg'
require 'pg'
ActiveRecord::Base.establish_connection(adapter: "postgresql", host: "localhost", user: "postgres", database: "test")
when 'mysql'
@hgupta
hgupta / setup.md
Last active August 29, 2015 13:57 — forked from georgeredinger/setup.md

./configure --prefix=/usr/local --enable-gui=yes --without-x --disable-nls --enable-multibyte --with-tlib=ncurses --enable-pythoninterp --enable-rubyinterp --with-ruby-command=/home/harsh/.rbenv/versions/2.1.5/bin/ruby --with-features=huge --enable-luainterp --enable-perlinterp

Ruby on Rails development setup on Ubuntu 12.04

System update

# change mirror to ubuntu.osuosl.org first
sudo apt-get update

Install common libraries

var empty_list = function(selector) {
return selector(undefined, undefined, true);
};
var prepend = function(el, list) {
return function(selector) {
return selector(el, list, false);
};
};
var head = function(list) {
#########################################
# Very basic rack application showing how to use a router based on the uri
# and how to process requests based on the HTTP method used.
#
# Usage:
# $ rackup rack_example.ru
#
# $ curl -X POST -d 'title=retire&body=I should retire in a nice island' localhost:9292/ideas
# $ curl -X POST -d 'title=ask Satish for a gift&body=Find a way to get Satish to send me a gift' localhost:9292/ideas
# $ curl localhost:9292/ideas