Skip to content

Instantly share code, notes, and snippets.

@elclanrs
elclanrs / F.js
Last active December 25, 2015 13:49
Overload JS functions
var F = (function() {
function typeOf(obj) {
return {}.toString.call(obj).slice(8,-1).toLowerCase();
}
function F(fns) {
return function() {
<?php
function wrap($text, $keywords, $tag = 'span')
{
$keywords = array_map(function($k){ return preg_quote($k); }, $keywords);
return preg_replace('/'. implode('|', $keywords) .'/i', "<$tag>$0</$tag>", $text);
}
$text = 'Scelerisque lectus aliquet egestas et placerat dis aliquet odio auctor in adipiscing in platea. Etiam rhoncus tortor tortor ut? Vel vel non elementum habitasse adipiscing, dis odio lundium sed mauris, urna phasellus a magna rhoncus non turpis, a, in urna non? Eu pellentesque lorem, porta scelerisque rhoncus sed massa in cum velit! Pulvinar. Magna ac dignissim, augue turpis magnis ut, arcu, duis? Ac porttitor rhoncus. Sagittis ut, pulvinar eros, tincidunt, facilisis pellentesque ridiculus, elementum tristique elit urna? Sed pulvinar vel quis? Dapibus cum nascetur, sed, cras pulvinar elementum? Augue.';
@elclanrs
elclanrs / script.sh
Last active December 23, 2015 13:49
Git Deployment
mkdir /srv/git
adduser myuser www-data
git init --bare --shared=group /srv/git/app.git
mkdir /var/www/app
chown -R www-data:www-data /srv/git/app.git /var/www/app
chmod -R g+rw /srv/git/app.git /var/www/app
vim /srv/git/app.git/hooks/post-receive
#!/bin/sh
export GIT_WORK_TREE=/var/www/app
@elclanrs
elclanrs / email-confirmation.php
Last active July 26, 2024 06:10
Simple e-mail confirmation plugin for WordPress.
<?php
/**
* Plugin Name: Email Confirmation
* Description: Send an email to the user with confirmation code and store form data in database until user confirms.
* Author: Cedric Ruiz
*/
class EmailConfirmation
{
const PREFIX = 'email-confirmation-';
<?php
// some php
?>
<html>
<head>
<script>
function logout() {
var r = confirm('Are you sure you want to logout?');
if (r) window.location.href = 'http://www.google.com';
@elclanrs
elclanrs / query.js
Last active December 22, 2015 00:00
Query.js: Small helper to parse and build URL queries.
// Generated by LiveScript 1.2.0
var query, vars;
query = {
parse: function(query){
var vars, patt;
vars = {};
patt = /[?&]([^&]+)=([^&]+)/g;
query = decodeURIComponent(query);
query.replace(patt, function(_, key, val){
return vars[key] = isNaN(val)
@elclanrs
elclanrs / remotegit.sh
Last active December 20, 2015 19:19
Setup remote git on Ubuntu VPS and Apache
# adduser myuser www-data
mkdir /var/www/site
git init --bare --shared=group /srv/git/repo.git
chgrp -R www-data /srv/git/repo.git /var/www/site
chmod g+rw /var/www/site
vim /srv/git/repo.git/hooks/post-receive
#!/bin/sh
export GIT_WORK_TREE=/var/www/site
git checkout -f
chmod +x /srv/git/repo.git/hooks/post-receive
var Example, example;
Example = (function() {
var someFunction;
Example.text = 'Hello world! ;)';
someFunction = function() {
return alert(this.getText());
};
<?php
$str = 'Hello world';
$word = 'world';
$res1 = preg_replace('/'.$word.'/i', '- $1 -', $str);
$res2 = preg_replace('/'.$word.'/i', '- $0 -', $str);
echo $res1;
echo '<br>';
@elclanrs
elclanrs / test.js
Last active December 20, 2015 04:09
$('#test').on('submit', function(){
var $required = $('input.required');
var $url = $('input[name=url]');
$required.add($url).removeClass('error');
var $invalid = $required.add($url).filter(function(){
return !this.value || !isValidUrl(this.value);
});