Skip to content

Instantly share code, notes, and snippets.

View kirankotari's full-sized avatar
:octocat:
Coming back up-to speed, need a bit more time.

Kiran Kumar Kotari kirankotari

:octocat:
Coming back up-to speed, need a bit more time.
View GitHub Profile
@kirankotari
kirankotari / input_typecast.py
Last active January 11, 2022 00:28
python input typecasting for major data types
from distutils import util
def _msg(args, msg=None):
msg = "input value error, please check your inputs." if msg is None else msg
return (f"{msg} {args[-1]}",)
def _try(func):
def wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
@kirankotari
kirankotari / class_instance_decorator.py
Last active July 12, 2021 16:09
Python Decorator dependent on Class Instance variables
def myDecorator(arg1, arg2, arg3=None):
def wrap(f):
def fun_wrap(self, *args, **kwargs):
# TODO: before calling function
print(f"before method call, {self.arg1}")
f(self, *args, **kwargs)
# TODO: after calling function
print(f"after method call, {self.arg1}")
return fun_wrap
return wrap
@emmasaunders
emmasaunders / readme.md
Last active October 10, 2023 16:40
How to import the sakila database into MySQL

##The old method, via phpmyadmin The first time I downloaded the sakila database, I did it via phpmyadmin using Import at the Server level. I did not use a command line. I did not create a database called Sakila and then populate it: the .sql files delete and re-create the database anyway. I imported the schema file and then the data file, ignoring the .mwb file, which is only useful if you have MySQL Workbench installed, at which point it supplies you a database diagram. A nice-to-have, but not critical in creating a database.

When I imported the files, I had to untick the box that said "Allow the interruption of an import in case the script detects...". I also had to temporarily change MySQL's maximum import size (using a line of SQL I found online): https://dev.mysql.com/doc/refman/5.5/en/packet-too-large.html

Today I find this method does not work. I get an error about geometry (which is due to a commented out line in the SQL). Even when I remove the commented out lines (whose purpose is to create spa

@sarahholderness
sarahholderness / emailer.py
Last active December 4, 2022 10:49
Python scripts to read a list of customer emails and send an email with the daily weather forecast
import weather
import smtp
'''
Send a greeting email to our customer email list
with the daily weather forecast and schedule
'''
def get_emails():
# Reading emails from a file
@FrancesCoronel
FrancesCoronel / sampleREADME.md
Last active March 26, 2024 01:21
A sample README for all your GitHub projects.

Repository Title Goes Here

Frances Coronel

INSERT GRAPHIC HERE (include hyperlink in image)

Subtitle or Short Description Goes Here

ideally one sentence >

@wpscholar
wpscholar / vagrant-cheat-sheet.md
Last active June 26, 2024 13:23
Vagrant Cheat Sheet

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
  • vagrant init <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)
@m00nlight
m00nlight / gist:a076d3995406ca92acd6
Last active October 21, 2020 21:31
Python merge sort in place, so space complexity is O(1)
import random
def merge_sort(xs):
"""Inplace merge sort of array without recursive. The basic idea
is to avoid the recursive call while using iterative solution.
The algorithm first merge chunk of length of 2, then merge chunks
of length 4, then 8, 16, .... , until 2^k where 2^k is large than
the length of the array
"""
@alan-mushi
alan-mushi / json_parser.c
Last active March 25, 2024 19:23
Examples for the json-c tutorial.
/*
* A simple example of json string parsing with json-c.
*
* clang -Wall -g -I/usr/include/json-c/ -o json_parser json_parser.c -ljson-c
*/
#include <json.h>
#include <stdio.h>
int main() {
struct json_object *jobj;
@azam
azam / svg2ico.sh
Last active April 28, 2024 03:28
Convert SVG to ICO using ImageMagick, with transparent background and multi-size icons
convert -density 256x256 -background transparent favicon.svg -define icon:auto-resize -colors 256 favicon.ico
@mistahenry
mistahenry / file_io.scala
Created April 19, 2014 21:56
Read file into List of lines in Scala
import scala.io.Source
val listOfLines = Source.fromFile("filename.txt").getLines.toList