Skip to content

Instantly share code, notes, and snippets.

@rashivkp
rashivkp / tunnel_dot.sh
Last active March 15, 2021 12:15
running local tunnel with nginx
# find mkcert ca path
# mkcert -CAROOT
# running local tunnel with local https server (nginx), using self signed certificates (mkcert),
lt --local-host api.dot.test --port 443 --subdomain dotapi --local-key /home/rashi/src/local-ssl-keys/_wildcard.dot.test+4-key.pem --local-ca /home/rashi/.local/share/mkcert/rootCA.pem --local-cert /home/rashi/src/local-ssl-keys/_wildcard.dot.test+4.pem --local-https true
@rashivkp
rashivkp / app.py
Created February 21, 2019 12:39
return helloworld for every route
from flask import Flask
from werkzeug.routing import BaseConverter
app = Flask(__name__)
class RegexConverter(BaseConverter):
def __init__(self, url_map, *items):
super(RegexConverter, self).__init__(url_map)
self.regex = items[0]
@rashivkp
rashivkp / convert_to_ogg.py
Last active July 29, 2020 06:35
Convert aac, amr files in a folder to ogg format with same name. And remove original file.
#! /usr/bin/python
import sys
from subprocess import call
import os.path
dest_ext = "ogg"
def convert(source):
print("Source: " + source)
extension = source[-3:]
@rashivkp
rashivkp / split.rb
Created March 14, 2017 14:33 — forked from venj/split.rb
Split a image into two halves.
#!/usr/bin/env ruby
require "fileutils"
(puts "Usage: #{File.basename $0} widthxheight"; exit 0) if ARGV.size != 1
width, height = ARGV[0].split("x").collect(&:to_i)
(puts "Please enter a valid size."; exit 0) if ((width.to_i == 0) or (height.to_i == 0))
half_width = width / 2
FileUtils.cd("images") do
Dir['**/*'].each do |f|
@rashivkp
rashivkp / ajax.php
Created September 11, 2016 19:49
php ajax sample json response
<?php
if (isset($_POST['name'])) {
header('Content-type: application/json');
if ($_POST['name'] != 'hi') {
$array = ['result' => 'fail', 'data' => '100'];
} else {
$array = ['result' => 'success', 'data' => '100'];
}
die(json_encode($array));
@rashivkp
rashivkp / sanchai-userscript.js
Created January 19, 2016 05:49
sanchai mapping - userscript to ease the data entry
// ==UserScript==
// @name so
// @namespace ALL
// @version 1
// @grant none
// @include http://sanchaya.lsgkerala.gov.in/assessment/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://greasyfork.org/scripts/1003-wait-for-key-elements/code/Wait%20for%20key%20elements.js?version=49342
// ==/UserScript==
// ==UserScript==

book : The Elements of Computing Systems

@rashivkp
rashivkp / linkedin-icon-for-jekyll-footer.html
Last active June 21, 2022 06:00
linkedin svg icon for jekyll page footer
@rashivkp
rashivkp / presentation-jupyter.ipynb
Created December 17, 2015 18:17
presentation notebook on jupyter. Install https://github.com/damianavila/RISE to show it as presentation within the notebook itself.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
select distinct student, date, sum(if(ifnull(k1.hour, 0)>0, 1, 0)) as fornoon,
sum(if(ifnull(k2.hour, 0)>0, 1, 0)) as afternoon from t1
left join t1 k1 on k1.student=t1.student, k1.date=t1.date and hour between 1, 4
left join t1 k2 on k2.student=t1.student, k2.date=t1.date and hour between 5, 7
; another approach, not tested
SELECT student, date
count(CASE WHEN t1.hour between 1,4 THEN 1 END ) AS fornoon,