Skip to content

Instantly share code, notes, and snippets.

View Neoglyph's full-sized avatar
🧙
wizard in training since 1989

Adam Stradovnik Neoglyph

🧙
wizard in training since 1989
View GitHub Profile
@Neoglyph
Neoglyph / split-camel-dash.js
Created July 3, 2017 13:04
Split camel case with dashes (-)
camelCase.replace(/([A-Z])/g, function (g) {
return "-" + g[0].toLowerCase();
})
@Neoglyph
Neoglyph / object-property-loop.js
Last active July 3, 2017 13:11
Loop through object properties
for (let property in object) {
if (object.hasOwnProperty(property)) {
// do stuff
}
}
@Neoglyph
Neoglyph / split-camel-dash-oneline.js
Created July 3, 2017 13:27
Split camel case with dashes - oneline
camelCase.replace(/([A-Z])/g, '-$1').toLowerCase()
@Neoglyph
Neoglyph / serialize-form-jquery.js
Created July 4, 2017 07:50
Serialize form data to JSON with jQuery
$.fn.serializeFormJSON = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
@Neoglyph
Neoglyph / utf8-base64-decode.js
Created September 19, 2017 22:09
UTF-8 base64 decode
// base64 decode and utf-8 decode the base64 encoded string
let encodedData = 'base64encodedstring...';
let decodedData = JSON.parse(decodeURIComponent(Array.prototype.map.call(atob(encodedData), function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join('')));
@Neoglyph
Neoglyph / utf8-base64-encode.js
Created September 19, 2017 22:43
UTF8 Base64 encode
function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
@Neoglyph
Neoglyph / response_codes_symfony.php
Created October 27, 2017 07:31
Symfony response codes
<?php
const HTTP_CONTINUE = 100;
const HTTP_SWITCHING_PROTOCOLS = 101;
const HTTP_PROCESSING = 102; // RFC2518
const HTTP_OK = 200;
const HTTP_CREATED = 201;
const HTTP_ACCEPTED = 202;
const HTTP_NON_AUTHORITATIVE_INFORMATION = 203;
const HTTP_NO_CONTENT = 204;
const HTTP_RESET_CONTENT = 205;
@Neoglyph
Neoglyph / remove-events.php
Created November 13, 2017 14:02
Remove events - Laravel Model
$dispatcher = Model::getEventDispatcher()
// Remove Dispatcher Model::unsetEventDispatcher()
//DO THINGS $model->save();
// Re-add Dispatcher Model::setEventDispatcher($dispatcher);
@Neoglyph
Neoglyph / chrome-autofill.css
Created January 4, 2018 12:57
Remove chrome autofill input background
/* Change background color */
input:-webkit-autofill {
-webkit-box-shadow: 0 0 0 30px white inset;
}
/* Change text color */
input:-webkit-autofill {
-webkit-text-fill-color: black !important;
}
@Neoglyph
Neoglyph / capital_count.php
Created January 18, 2018 12:33
Count capital leters inside a sentence
<?php
public static function countCapitalLetters($string){
$lowerCase = mb_strtolower($string);
return strlen($lowerCase) - similar_text($string, $lowerCase);
}