Skip to content

Instantly share code, notes, and snippets.

View nulpatrol's full-sized avatar

Rostyslav Khaniukov nulpatrol

View GitHub Profile
@nulpatrol
nulpatrol / snippet1.java
Last active August 29, 2015 14:25
Iterating Map<Object, Set<Object>>
for (Map.Entry<String, Set<String>> rule : rules.entrySet()) {
String key = rule.getKey();
Set<String> value = rule.getValue();
for (String temp : value) {
System.out.println("Scope: " + key + ", rule: " + temp);
}
}
@nulpatrol
nulpatrol / log4j2.xml
Created July 27, 2015 09:35
Log4j version 2 config
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<File name="console" filename="log/console.log" immediateFlush="true">
<PatternLayout pattern="[%d{dd/MM/YYYY HH:mm:ss}]%n%msg%n" />
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY" />
</File>
<File name="requests" filename="log/requests.log" immediateFlush="true">
<PatternLayout pattern="%d{dd/MM/YYYY HH:mm:ss} - %msg%n" />
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY" />
@nulpatrol
nulpatrol / IPUtil.java
Created July 28, 2015 06:31
Pack and unpack IP address (InetAddress) to/from int
public static int pack(byte[] bytes) {
int val = 0;
for (byte oneByte : bytes) {
val <<= 8;
val |= oneByte & 0xff;
}
return val;
}
public static short[] unpack(int bytes) {
@nulpatrol
nulpatrol / AutoIncrement.sql
Last active March 14, 2016 09:24
AutoIncrement.sql
CREATE TABLE people (
id NUMBER NOT NULL,
name VARCHAR(56),
last_name VARCHAR(56),
dob DATE,
graduation_date DATE,
created_at TIMESTAMP,
updated_at TIMESTAMP)
ALTER TABLE people ADD CONSTRAINT people_pk PRIMARY KEY ( id )
@nulpatrol
nulpatrol / autocomplete.php
Created September 21, 2016 18:07 — forked from imranismail/autocomplete.php
Laravel And JqueryUI's Autocomplete Plugin
//SearchController.php
public function autocomplete(){
$term = Input::get('term');
$results = array();
$queries = DB::table('users')
->where('first_name', 'LIKE', '%'.$term.'%')
->orWhere('last_name', 'LIKE', '%'.$term.'%')
->take(5)->get();
@nulpatrol
nulpatrol / gist.php
Created November 9, 2016 13:17
Where static method defined
$reflectionMethod = new ReflectionMethod('Auth::routes');
print $reflectionMethod->getFileName() . ':' . $reflectionMethod->getStartLine();
@nulpatrol
nulpatrol / git.txt
Last active February 21, 2017 11:25
Git CheatSheet
"git checkout ." - delete local changes
"git config --global credential.helper wincred" - save credentials
git checkout --ours .
git checkout --theirs .
To remove untracked files / directories do:
git clean -fdx
-f - force
-d - directories too
-x - remove ignored files too ( don't use this if you don't want to remove ignored files)
@nulpatrol
nulpatrol / console_route.php
Created January 18, 2017 15:30
console route
<?php
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->describe('Display an inspiring quote');
@nulpatrol
nulpatrol / .htaccess
Created January 19, 2017 09:33
HTTP Auth
AuthType Basic
AuthName "Login please"
AuthUserFile "/home/sumdu/dias.team/dvv/.htpasswd"
Require valid-user
public function changePassword()
{
try {
$user = User::findOrFail(request()->input('id'));
if (Hash::check(request()->input('password'), $user->password)) {
throw ValidationException::withMessages([
'password' => ['translation.newPasswordMustBeDifferent']
]);
}