Skip to content

Instantly share code, notes, and snippets.

View ayushgoel's full-sized avatar

Ayush ayushgoel

View GitHub Profile
@ayushgoel
ayushgoel / shell-commands.rb
Last active August 29, 2015 14:22 — forked from JosephPecoraro/shell-execution.rb
Running shell commands from ruby
# Ways to execute a shell script in Ruby
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
value = `echo 'hi'` # or uglier but valid => Kernel.`("echo 'hi'")
@ayushgoel
ayushgoel / GoogleSearch_0.3.py
Created June 1, 2015 15:31
Google code closure lead this script here. Gives an iterator over google search results.
#!/usr/bin/env python
## DESCRIPTION
## The script provides an iterator over the search results returned by google, after giving a query.
##
## EXAMPLES
## TODO: Show some examples of how to use this script.
##
## EXIT STATUS
## No exit statuses provided. The class simply returns an iterator over the results. Only error raised is the StopIteration.
# Aloha number - number with all digits '4' or '7'
# Q - Given a number, find the aloha number just greater or equal to given number.
def alt(s):
# print "Number: ", s
if s == '4':
return '7'
elif s == '7':
return '44'
# s = str(n)
i = s.find('8') if s.find('8') != -1 else s.find('9')
@ayushgoel
ayushgoel / ios-icons.py
Last active August 29, 2015 14:20
Convert one image to all required sizes for iOS icons and artwork with understandable names
#!/usr/bin/env python3
import PIL.Image as Image
import sys
extension = ".png"
def saveImage(image, imageName):
image.save(imageName + extension)
@ayushgoel
ayushgoel / UIViewController+PerformSegueOnMainQueue.swift
Created April 12, 2015 11:12
Perform segue only on main queue
import UIKit
extension UIViewController {
func performSegueOnMainQueue(identifier: String, sender: AnyObject?) {
NSOperationQueue.mainQueue().addOperationWithBlock() {
self.performSegueWithIdentifier(identifier, sender: sender)
}
}
@ayushgoel
ayushgoel / .gitignore
Last active January 27, 2022 18:46
Create a post file to be used in Jekyll aware blogs.
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# Distribution / packaging
.Python
env/
build/
develop-eggs/
@ayushgoel
ayushgoel / removeFirst3Chars.py
Created December 9, 2014 08:20
Rename all files in current folder - remove first 3 chars
for i in os.listdir('.'):
if i.startswith('.') == False: #Hidden files
os.rename(i, i[3:])
@ayushgoel
ayushgoel / euler52.py
Last active August 29, 2015 14:08
Project Euler 52
def digits(x):
return set([int(j) for j in str(x)])
x = 1000
while True:
#write code
y = int(1.668*x)
for i in range(x, y):
print i
@ayushgoel
ayushgoel / git-subtree-add
Last active August 29, 2015 14:08
Easily add git subtree
#!/usr/bin/env bash
if [ $# -lt 2 ]
then
echo "ERROR: Less arguments."
echo "Usage: git-subtree-add <git-url> <ref(commit)>"
else
REPO_NAME=`echo $1 | sed 's%^.*/\([^/]*\)\.git$%\1%g'`
echo "Adding subtree for "
echo $REPO_NAME
@ayushgoel
ayushgoel / hex-to-color
Created September 9, 2014 09:31
Convert Hex value for colour to decimal (cfcfcf) -> (207 207 207)
#! /usr/bin/python
import sys
def colorForHex(x):
if len(x) != 6:
return "Poorly formatted HEX", x
try:
r = int(x[:2], 16)
g = int(x[2:4], 16)