Skip to content

Instantly share code, notes, and snippets.

View viveksoundrapandi's full-sized avatar

Vivek Soundrapandi viveksoundrapandi

View GitHub Profile

Keybase proof

I hereby claim:

  • I am viveksoundrapandi on github.
  • I am iamvivek (https://keybase.io/iamvivek) on keybase.
  • I have a public key ASDG6zN7ypopbFRy62WHXPLvWx0rrBLRiW4jfZ19MF9VbAo

To claim this, I am signing this object:

# frozen_string_literal: true
class Proc
def my_curry
# when my_curry is called: create a new proc and return
curried = proc do |*partial_args|
# when curried proc is called: create a closure with partial arguments and then return a new proc/lambda
l = lambda do |*remaining_args|
# when the partial rendered curried lambda is called delegate the call to original lambda with closure + current arguments
actual_args = partial_args + remaining_args
@viveksoundrapandi
viveksoundrapandi / curry-ruby-native.c
Created January 16, 2020 03:53
curry ruby native version
From: proc.c (C Method):
Owner: Proc
Visibility: public
Number of lines: 19
static VALUE
proc_curry(int argc, const VALUE *argv, VALUE self)
{
int sarity, max_arity, min_arity = rb_proc_min_max_arity(self, &max_arity);
VALUE arity;
@viveksoundrapandi
viveksoundrapandi / pupeteer-demo.js
Last active August 27, 2019 13:08
Jazz cinemas ticket booking automation with puppeteer
const puppeteer = require('puppeteer');
// Entry point to begin the flow
const scrapeImages = async (movie_details) => {
console.log(`Initiating ticket booking for ${movie_details.username}`);
// launch the chrome broser
const browser = await puppeteer.launch( { headless: false, dumpio: true, args: ['--no-sandbox']});
// Open a new Tab
const page = await browser.newPage();
// Visit our target website
await page.goto('https://www.jazzcinemas.com/Customer/Login');
@viveksoundrapandi
viveksoundrapandi / .py
Last active August 14, 2019 13:40
forwardable getattr for medium
def __getattr__(self, name):
# EX: delegates = [("q", "enqueue", "append")]
#iterate through to delegate items
for attr in self.delegates:
#check if the current lookedup attribute is in any of the delegates
if name == attr[1] and hasattr(getattr(self, attr[0]), attr[2]):
#delegate the call to composed object
return getattr(getattr(self, attr[0]), attr[2])
#raise AttributeError to mimick system default
raise AttributeError("'{}' object has no attribute '{}'".format(type(self).__name__, name))
@viveksoundrapandi
viveksoundrapandi / .py
Last active May 19, 2020 08:36
Forwardable in python
class Forwardable(object):
def __init__(self, *args, **kwargs):
self._delegates = []
return super().__init__(*args, **kwargs)
@property
def delegates(self):
return self._delegates
@delegates.setter

Keybase proof

I hereby claim:

  • I am viveksoundrapandi on github.
  • I am iamvivek (https://keybase.io/iamvivek) on keybase.
  • I have a public key whose fingerprint is 1FBF 6AE2 C596 E799 1AA1 7349 E9A6 7B04 F328 D4E2

To claim this, I am signing this object:

@viveksoundrapandi
viveksoundrapandi / fresh_install_of_osx.sh
Created February 18, 2019 12:42 — forked from vraravam/fresh-install-of-osx.sh
Steps to get "up and running" with new Mac OSX
#!/usr/bin/env bash
##################################
# Install command line dev tools #
##################################
/usr/bin/xcode-select -p > /dev/null 2>&1
if [ $# != 0 ]; then
xcode-select --install
sudo xcodebuild -license accept
fi
@viveksoundrapandi
viveksoundrapandi / merge_files
Created May 22, 2014 06:22
merge text files in a directory
for %f in (*.txt) do type "%f" >> output.txt
@viveksoundrapandi
viveksoundrapandi / python django create and download zip
Created March 17, 2014 14:52
A simple snippet to zip files in a directory and send it the browser in downloadable format in django
from shutil import make_archive
from django.core.servers.basehttp import FileWrapper
def download(request,file_name=""):
"""
A django view to zip files in directory and send it as downloadable response to the browser.
Args:
@request: Django request object
@file_name: Name of the directory to be zipped
Returns:
A downloadable Http response