Skip to content

Instantly share code, notes, and snippets.

View rajiteh's full-sized avatar
🅱️
'sup

Raj Perera rajiteh

🅱️
'sup
  • @ubisoftinc
  • Toronto, ON
View GitHub Profile
@rajiteh
rajiteh / tcpserver.sh
Created September 7, 2016 20:40
Simple TCP listener
while true; do echo "HELLO FROM THE OTHER SIDE" | perl -MIO::Socket::INET -ne 'BEGIN{$l=IO::Socket::INET->new(LocalPort=>31337,Proto=>"tcp",Listen=>5,ReuseAddr=>1);$l=$l->accept}print $l $_';done
@rajiteh
rajiteh / switch-rancheros-docker.sh
Last active January 9, 2022 09:01
RancherOS docker version updater.
#!/bin/bash
# RancherOS docker version updater.
# Author: @rajiteh
# License: BSD
#
# How to use:
# You need to use a persistent console (tested on ubuntu).
# Set up the script to be called at console initalization time.
#
# Example cloud-config.yml usage.
@rajiteh
rajiteh / media_station.ps1
Last active July 2, 2016 18:39
Run sabnzbd, couchpotato, and sickrage on docker, on windows.
$LogLineContext = "MAIN"
Function LogLine($msg, $context)
{
if($context -ne $null) {
$script:LogLineContext = $context
}
Write-host "[$($LogLineContext)]:" $msg
}
function RunCommand($cmd) {
@rajiteh
rajiteh / dhclient_keepalive.sh
Created April 25, 2016 20:09
keep alive script to ensure dhclient is running all the time
#!/usr/bin/env bash
# This script should be run periodically to ensure that dhclient process is active.
pidfile_glob="/run/dhclient*"
regex="/run/dhclient\.([a-z]+[0-9]+)\.pid"
matched=0
function _logger() {
logger "DHCLIENT KEEPALIVE: " $@
echo "DHCLIENT KEEPALIVE: " $@
}
@rajiteh
rajiteh / telegram_ghetto_image_download.js
Last active April 21, 2016 01:53
ghetto-est way to dump images from a telegram chat. just paste the damn thing in your console. works with web.telegram.org
var withJquery = function(callback, version) {
if (typeof version == "undefined") { version = "2.1.1"; }
var script = document.createElement("script");
script.src = "https://code.jquery.com/jquery-" + version + ".min.js";
script.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(script);
var interval = setInterval(function() {
if (typeof jQuery === "function") {
window.$ = jQuery;
clearInterval(interval);
@rajiteh
rajiteh / mongo_defined_search_n_replace.js
Created February 19, 2016 01:43
Traverses a defined set of collections and replaces a nested value in the document. Nested arrays handled automatically. (mongodb js)
/*
Traverses a defined set of collections and replaces a nested value in the document. Nested arrays handled automatically.
Author: @rajiteh
Usage:
var searches =
{
'collection_name': [
[ 'key', 'sub_key', 'sub_sub_key', ... ], // Path to target value.
...
@rajiteh
rajiteh / mongo_search_and_replace.js
Created February 18, 2016 17:48
Recursively search and replace a string value across all collections in a mongodb database.
/*
Recursively traverses all collections and objects/arrays contained within documents replacing every
instance of 'find' with 'replace'.
mongo <db_name> mongo_search_and_replace.js
*/
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
@rajiteh
rajiteh / pedantically_commented_playbook.yml
Created October 23, 2015 11:24 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
@rajiteh
rajiteh / _bootstrap.php
Last active August 29, 2015 14:25
Quickly bootstrap your laravel database using an alternate .env file (Can be used with Codeception)
<?php
class LaravelTestDatabaseBootstrapper {
protected static $_instance;
protected $projectRoot;
protected $envFile;
protected $app = null;
protected function __construct($envFile, $projectRoot) {
@rajiteh
rajiteh / 0_reuse_code.js
Last active August 29, 2015 14:23
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console