Skip to content

Instantly share code, notes, and snippets.

@iHamex
iHamex / Function.Array-Group-By.php
Created March 31, 2019 02:01 — forked from mcaskill/Function.Array-Group-By.php
PHP : Groups an array by a given key
<?php
if (!function_exists('array_group_by')) {
/**
* Groups an array by a given key.
*
* Groups an array into arrays by a given key, or set of keys, shared between all array members.
*
* Based on {@author Jake Zatecky}'s {@link https://github.com/jakezatecky/array_group_by array_group_by()} function.
* This variant allows $key to be closures.
@iHamex
iHamex / rm-ite.sh
Created July 18, 2018 13:32 — forked from amio/rm-ite.sh
Remove ''www.it-ebooks.info" from pdf.
#!/bin/bash
source_dir=$1;
find "$1" -type f -name "*.pdf" -print0|while read -d $'\0' file;
do
if [ `strings "$file"|grep -c "www.it-ebooks.info"` -gt 0 ];
then
echo "$file";
cp "$file" /tmp/1.pdf;
script=$(cat <<'EOF'
use strict;
@iHamex
iHamex / encryption.java
Created July 15, 2018 08:08 — forked from itarato/encryption.java
Java AES CBC encryption example
package com.company;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.MessageDigest;
import java.security.SecureRandom;
public class Main {
@iHamex
iHamex / openssl_encrypt_decrypt.php
Created June 6, 2018 03:25 — forked from joashp/openssl_encrypt_decrypt.php
Simple PHP encrypt and decrypt using OpenSSL
<?php
/**
* simple method to encrypt or decrypt a plain text string
* initialization vector(IV) has to be the same when encrypting and decrypting
*
* @param string $action: can be 'encrypt' or 'decrypt'
* @param string $string: string to encrypt or decrypt
*
* @return string
*/
@iHamex
iHamex / Password.java
Created February 13, 2018 19:21 — forked from craSH/Password.java
A simple example Java class to safely generate and verify bcrypt password hashes for use in authentication systems.
/**
* Author: Ian Gallagher <igallagher@securityinnovation.com>
*
* This code utilizes jBCrypt, which you need installed to use.
* jBCrypt: http://www.mindrot.org/projects/jBCrypt/
*/
public class Password {
// Define the BCrypt workload to use when generating password hashes. 10-31 is a valid value.
private static int workload = 12;
@iHamex
iHamex / Cross Browser Persian Type with jQuery
Created December 7, 2017 16:10
Cross Browser Persian Type with jQuery
var keyboardLayout={};
var langCycle=[''];
(function($){var k=null;var tt=null;function sh(l){var t='Language: ';for(var i=0;i<langCycle.length;i++){var x=lfc(i)||'default';t+=(i==l?'['+x+']':x)+' ';}if(tt)clearTimeout(tt);document.t=document.t||document.title;document.title=t;tt=setTimeout(function(){document.title=document.t;document.t=undefined;tt=null;},1000);}function lfc(i){return langCycle[i].lang?langCycle[i].lang:langCycle[i];}function dfc(i){return langCycle[i].direction?langCycle[i].direction:'';}function nli(t){var ni=langCycle.length?0:-1;for(var i=0;i<langCycle.length;i++){if(lfc(i)==t)ni=i<langCycle.length-1?i+1:0;}return ni;}$('input[type=text],textarea').on('keydown',function(e){k=e.which;}).on('keypress',function(e){var $t=$(this);var l=$t.attr('lang').match(/^[a-zA-Z]{2}/)||'';if(!l){if(!langCycle.length) return true;l=lfc(0);}if (e.ctrlKey&&e.which==0x20&&langCycle&&langCycle.length>1){var nl=nli(l);if(nl>=0){sh(nl);$t.attr('lang',lfc(nl));$t.css('direction',dfc(nl));}e.preventDefault();re
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service
@iHamex
iHamex / gist:973a689b8bd3607f23da1d607f782114
Created February 19, 2017 14:15 — forked from victoredwardocallaghan/gist:9425974
Stopping SSH Brute Force attacks with PF.
# Make table to keep track of IP's of SSH brute forcers:
table <bruteforce> persist
# Make sure they are unable to connect to the system after being appended to table:
block quick from <bruteforce>
# The rule how one is appended to the table..
# By connecting with more then 5 clients to the SSH port
# and try reconnect 5 times within 30 secs, append client machine to the table:
pass inet proto tcp from any to any port ssh \
@iHamex
iHamex / browse.php
Created February 12, 2017 07:00 — forked from erikhatcher/browse.php
PHP Solr Example
<?php
class Solr {
var $base_url;
var $request;
var $action;
var $q;
var $filter_queries;
var $sort;
var $results_per_page;