Skip to content

Instantly share code, notes, and snippets.

@Kichrum
Kichrum / dateTimeFilter.js
Last active Aug 29, 2015
Just convert '2015-08-02T00:00:00Z' to '2015-08-02 00:00:00'
View dateTimeFilter.js
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 / camelCaseToCapitalized.js
Created Apr 2, 2015
Angular filter to replace camelCase string with Capitalized String
View camelCaseToCapitalized.js
(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 / customValuesFilter.js
Created Mar 11, 2015
Angular.js filter for adding custom values in brackets
View customValuesFilter.js
(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 / auto_increment.sql
Created Aug 13, 2014
AUTO_INCREMENT: getter and setter
View auto_increment.sql
-- 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 / downloadWebsite.sh
Created Jul 29, 2014
Download an entire website
View downloadWebsite.sh
wget -r --no-parent http://site.com/songs/
@Kichrum
Kichrum / fileModel.php
Created Jul 28, 2014
Get file path by file name in database - Yii
View fileModel.php
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 / inject_script.js
Created Jul 22, 2014
Helper function to inject a <script> tag
View inject_script.js
// 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 / video_converter.sh
Last active Aug 29, 2015
Convert video files to mp4, webm, flv and png formats
View video_converter.sh
#!/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 / inherit_es5.js
Created Jul 22, 2014
Inheritance in JavaScript for EcmaScript 5
View inherit_es5.js
/**
* Inheritance in ES5
* @author Kichrum
*/
var inherit = function(Parent) {
var Child = function(){ Parent.apply(this, arguments) }
Child.prototype = Object.create(Parent.prototype)
return Child
}
@Kichrum
Kichrum / inherit.js
Last active Aug 29, 2015
Inheritance in JavaScript for EcmaScript 3
View inherit.js
/**
* 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:
You can’t perform that action at this time.