Skip to content

Instantly share code, notes, and snippets.

@Kichrum
Kichrum / inherit.js
Last active August 29, 2015 14:04
Inheritance in JavaScript for EcmaScript 3
/**
* One more version of inheritance for ES3
* @author Kichrum
*/
var inherit = function(Parent) {
var Child = function(){ Parent.apply(this, arguments) }
// We can use
// Child.prototype = Object.create(Parent.prototype)
// here for ES5 instead of next 3 lines:
@Kichrum
Kichrum / video_converter.sh
Last active August 29, 2015 14:04
Convert video files to mp4, webm, flv and png formats
#!/bin/bash
#author : Kichrum
files=$(ls *.avi);
outputFolder="output/"
for file in $files
do
outputFile=${file//.avi/};
printf "\n\n === Converting $file => $outputFile.mp4 === \n";
@Kichrum
Kichrum / inject_script.js
Created July 22, 2014 07:41
Helper function to inject a <script> tag
// Helper function to inject a <script> tag.
function injectScript(url, onload, onerror) {
var script = document.createElement("script");
// onload fires even when script fails loads with an error.
script.onload = onload;
script.onerror = onerror || onload;
script.src = url;
document.head.appendChild(script);
}
@Kichrum
Kichrum / fileModel.php
Created July 28, 2014 13:55
Get file path by file name in database - Yii
class File extends CActiveRecord
{
public function rules()
{
array('filename', 'file', 'types'=>'pdf, doc, docx, xls, xlsx, ods, odt, zip, rar, avi, mp4, flv, txt, webm', 'allowEmpty' => true),
);
}
/**
* Get file path by file name in database
@Kichrum
Kichrum / downloadWebsite.sh
Created July 29, 2014 08:17
Download an entire website
wget -r --no-parent http://site.com/songs/
@Kichrum
Kichrum / auto_increment.sql
Created August 13, 2014 09:47
AUTO_INCREMENT: getter and setter
-- Get AUTO_INCREMENT current value:
SELECT `AUTO_INCREMENT`
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'DatabaseName'
AND TABLE_NAME = 'TableName';
-- SET AUTO_INCREMENT value (this number will be user for NEXT inserted element):
ALTER TABLE `TableName` AUTO_INCREMENT = 5;
@Kichrum
Kichrum / customValuesFilter.js
Created March 11, 2015 11:16
Angular.js filter for adding custom values in brackets
(function(angular) {
var addCustomValuesFilter = function () {
// string | addCustomValues : true : 1 : 2
return function () {
var input = arguments[0],
shouldApplyFilter = arguments[1] !== false,
i, len,
values = [],
result = input;
if (shouldApplyFilter) {
@Kichrum
Kichrum / camelCaseToCapitalized.js
Created April 2, 2015 10:31
Angular filter to replace camelCase string with Capitalized String
(function(angular) {
// 'camelCaseName' | camelCaseToCapitalized => 'Camel Case Name'
var camelCaseToCapitalizedFilter = function() {
return function(string) {
return string
.replace(/([A-Z])/g, ' $1')
.replace(/^./, function(str) {
return str.toUpperCase();
});
};
@Kichrum
Kichrum / dateTimeFilter.js
Last active August 29, 2015 14:27
Just convert '2015-08-02T00:00:00Z' to '2015-08-02 00:00:00'
angular.module('date-time-filter')
.filter('dateTimeFilter', () => input => 'string' === typeof input ? input.replace(/^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})Z$/, '$1 $2') : input);
@Kichrum
Kichrum / relevanssi.diff
Last active December 26, 2015 23:19
Relevanssi comma separate fix.
diff --git a/wp-content/plugins/relevanssi/lib/common.php b/wp-content/plugins/relevanssi/lib/common.php
index 5ac8d4b..a797aaa 100644
--- a/wp-content/plugins/relevanssi/lib/common.php
+++ b/wp-content/plugins/relevanssi/lib/common.php
@@ -396,7 +396,7 @@ function relevanssi_get_custom_fields() {
return $custom_fields;
}
else {
- $custom_fields = explode(",", $custom_fields);
+ $custom_fields = explode("\n", $custom_fields);