Skip to content

Instantly share code, notes, and snippets.

View qa1's full-sized avatar
🎯
Focusing

qa1

🎯
Focusing
View GitHub Profile
@branneman
branneman / gist:951847
Last active January 27, 2021 18:42
array_find() - A case insensitive array_search() with partial matches
<?php
/**
* Case in-sensitive array_search() with partial matches
*
* @param string $needle The string to search for.
* @param array $haystack The array to search in.
*
* @author Bran van der Meer <branmovic@gmail.com>
* @since 29-01-2010
*/
@m4rcsch
m4rcsch / validatorIsUnique.php
Created March 8, 2012 10:49
isUnique Validator for Lithium (li3) PHP Framework
Validator::add('isUnique', function($data, $params, $options) {
$model = $options['model'];
$field = $options['field'];
$key = $model::meta('key');
$entity = $model::first(array('conditions' => array($field => $data)));
$identifier = isset($options['values'][$key]) ? $options['values'][$key] : null;
if ($entity && $entity->data() && $identifier == (string) $entity->$key) {
@zekizeki
zekizeki / mqttpublish.php
Last active December 9, 2020 23:33
Simple pure MQTT publish client written in PHP
<?php
/**
*
* The MQTTClient class allows you to connect to an MQTT message broker and publish messages
* @author rob.s.smart@gmail.com
*
* Example use
* $client = new MQTTClient("robphptest","realtime.ngi.ibm.com",1883);
* $client->connect();
@joshhartman
joshhartman / array_diff_example.php
Created December 20, 2012 01:48
Example: array_diff() vs. array_diff_assoc()
<?php
$a = array('z'=>1, 'a'=>5, 'e'=>'7');
$b = array('a'=>3, 'g'=>5, 'x'=>7);
$c = array_diff($a, $b);
$d = array_diff_assoc($a, $b);
echo '<b>$a</b> = ';
var_dump($a);
echo '</br><b>$b</b> = ';
var_dump($b);
echo '</br><h2>array_diff($a, $b) Result</h2>';
@ebraminio
ebraminio / gist:5292017
Last active July 2, 2024 06:14
Check Iranian National Code Validity - بررسی صحت کد ملی ایرانی - Clojure, C#, F#, Ruby, JavaScript, Dart, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir, PowerQuery M Language, VBA, R, Lua, Fortran, Pascal/Delphi, Excel, Stored Procedure / MySQL
// Check Iranian National Code Validity - Clojure, C#, F#, Ruby, JavaScript, Dart, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir, Power Query M Language, VBA, R, Lua, Fortran, Pascal/Delphi, Excel, Stored Procedure / MySQL
// بررسی صحت کد ملی ایران - کلوژر، سی‌شارپ، اف‌شارپ، روبی، جاوااسکریپت، دارت، پایتون، اسکالا، جاوا ۸، پی‌اچ‌پی، سی، گو، سوئیفت، کاتلین، گرووی، راست، هسکل، ارلنگ، الکسیر، پاورکوئری ام، وی‌بی ای، آر، لوآ، فرترن، پاسکال/دلفی، اکسل، مای‌اس‌کیوال
// در نسخه‌های قبل یکسان بودن اعداد نا معتبر تشخیص داده می‌شد ولی
// اعداد یکسان نامعتبر نیست https://web.archive.org/web/20170706081048/http://www.fardanews.com/fa/news/127747/رندترین-شماره-ملی-بلای-جان-صاحبش-شد
// بعضی از پیاده‌سازی‌ها سریع نیستند، می‌توانید نسخهٔ خود را بر پایهٔ
// نسخهٔ سی یا گو ایجاد کنید که بهترین سرعت را داشته باشد
/**
@thoop
thoop / nginx.conf
Last active December 8, 2023 21:55
Official prerender.io nginx.conf for nginx
# Change YOUR_TOKEN to your prerender token
# Change example.com (server_name) to your website url
# Change /path/to/your/root to the correct value
server {
listen 80;
server_name example.com;
root /path/to/your/root;
index index.html;
@ismasan
ismasan / sse.go
Last active March 19, 2024 18:13
Example SSE server in Golang
// Copyright (c) 2017 Ismael Celis
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
@staltz
staltz / introrx.md
Last active July 15, 2024 15:43
The introduction to Reactive Programming you've been missing
@embayer
embayer / pythonUtf8.md
Last active October 30, 2020 06:21
set python default encoding to utf-8

change default encoding

cd ~/.virtualenvs/myvirtualenv/lib/python2.x/site-packages
echo 'import sys;sys.setdefaultencoding("utf-8")' > sitecustomize.py

set default encoding for each new virtualenv

to automatically create a sitecustomize.py every time you create a virtualenv, edit your

@Ocramius
Ocramius / README.md
Last active January 22, 2024 00:09
`__invoke` vs `function` vs `Closure`