Skip to content

Instantly share code, notes, and snippets.

@YasinPatel
YasinPatel / validation.js
Created July 19, 2017 07:06
Different custom validation in jquery validator
jQuery.validator.addMethod("alphanumeric", function(value, element) { // allow only alpha numric validation
return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
});
jQuery.validator.addMethod("letterwithspaces", function(value, element) { // allow only latters with space validation
return this.optional(element) || /^[a-zA-Z]+$/.test(value);
});
jQuery.validator.addMethod("imagetype", function(value, element) { // allow image validation
return this.optional(element) || /^.*\.(jpg|png|jpeg|gif)$/i.test(value);
@YasinPatel
YasinPatel / module.php
Last active January 16, 2019 07:48
Module wise Error Page in Yii2
Yii::$app->errorHandler->errorAction = 'studconsult/default/error';
<?php
namespace app\modules\admin;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'app\modules\admin\controllers';
import hashlib as hasher
import datetime as date
# Define what a Snakecoin block is
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
@YasinPatel
YasinPatel / Load default values in yii2 in model
Created June 28, 2017 06:53
Load default values in yii2 in model
1. by model :
[['attribute', 'second_attribute'], 'default', 'value' => 'something_here'],
2. load attributes in model
$model = new Post();
$model->loadDefaultValues();
@YasinPatel
YasinPatel / web.php
Created June 6, 2017 09:20
Mail setting in Yii2
// SMTP settings to send mail in yii2
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
@YasinPatel
YasinPatel / web.php
Last active July 19, 2017 07:19
Generate custom crud template in yii2
// To create custom admin layout template , Go to config/web.php and add below lines
'modules' => [
'gii' => [
'class' => 'yii\gii\Module', //adding gii module
'allowedIPs' => ['127.0.0.1','192.168.1.*'], //allowing ip's
'generators' => [
'crud' => [ // generator name
'class' => 'yii\gii\generators\crud\Generator', // generator class
'templates' => [ //setting for out templates
@davideast
davideast / bulkUpdate.js
Last active April 20, 2021 17:18
Bulk update with .push()
/**
* Send a bulk update to Firebase from an array or an object literal.
*
* When .push() is called on a Firebase reference without a parameter passed no
* trip to the server is made.
*
* ex:
* var childRef = ref.push();
*
* A reference is returned which has a push-id that can be returned by calling .name().