Skip to content

Instantly share code, notes, and snippets.

View nicklasos's full-sized avatar
💭
😅

Olkhovyk Mykyta nicklasos

💭
😅
View GitHub Profile
@nicklasos
nicklasos / dateformat.js
Last active August 29, 2015 13:55
So fucking JavaScript. Number format
function dateFormat(daysAgo) {
var d = new Date();
daysAgo = daysAgo || 0;
d.setDate(d.getDate() - daysAgo);
var date = d.getDate(),
month = d.getMonth() + 1,
year = d.getFullYear();
@nicklasos
nicklasos / ip.php
Created March 12, 2014 09:38
Get client ip
<?php
function get_client_ip()
{
if (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
} else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else if (isset($_SERVER['HTTP_X_FORWARDED'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
@nicklasos
nicklasos / csv_to_array.php
Created April 24, 2014 11:50
CSV to array
<?php
function csv_to_array($filename, $delimiter = ',')
{
if (!file_exists($filename) || !is_readable($filename)) {
return false;
}
$header = null;
$data = [];
<?php
/**
* Depend from csv_to_array and get_in functions
* @link https://gist.github.com/nicklasos/11251754
* @link https://gist.github.com/nicklasos/9206376
*/
function t($phrase)
{
static $dictionary;
<?php
if (!function_exists('array_column')) {
function array_column(array $input, $columnKey, $indexKey = null) {
$result = array();
if (null === $indexKey) {
if (null === $columnKey) {
// trigger_error('What are you doing? Use array_values() instead!', E_USER_NOTICE);
$result = array_values($input);
@nicklasos
nicklasos / json.cs
Last active August 29, 2015 14:01
C# Common functions
public struct MainPage
{
public string Threads { get; set; }
public List<Pager> Pages { get; set; }
}
public struct Pager
{
private string filename;
public string Filename
@nicklasos
nicklasos / mongoload.php
Last active August 29, 2015 14:02
Insert random data to mongo
<?php
include __DIR__ . '/vendor/autoload.php';
$faker = Faker\Factory::create();
$randData = [
'gmt_diff' => 'randomDigitNotNull',
'ios_id' => 'uuid',
'email' => 'email',
@nicklasos
nicklasos / varname.php
Last active August 29, 2015 14:02
Variable name
<?php
function variable_name(&$var)
{
$old = $var;
$var = $new = 'UNIQUE' . mt_rand() . 'VARIABLE';
$vname = false;
foreach($GLOBALS as $key => $val) {
if($val === $new) {
$vname = $key;
@nicklasos
nicklasos / mongo_id_from_time.php
Created July 2, 2014 12:56
Mongo id from time
<?php
function mongo_id_from_time($yourTimestamp)
{
static $inc = 0;
$ts = pack('N', $yourTimestamp);
$m = substr(md5(gethostname()), 0, 3);
$pid = pack('n', posix_getpid());
$trail = substr(pack('N', $inc++), 1, 3);
@nicklasos
nicklasos / prompt_password.php
Last active August 29, 2015 14:05
Prompt password
<?php
/**
* Interactively prompts for input without echoing to the terminal.
* Requires a bash shell or Windows and won't work with
* safe_mode settings (Uses `shell_exec`)
*
* @see http://us.php.net/manual/en/function.ncurses-noecho.php
* @see http://us.php.net/manual/en/function.ncurses-getch.php
*
* Works only on normal OS, not in windows.