Skip to content

Instantly share code, notes, and snippets.

@jrivero
jrivero / jsCookies.js
Last active February 21, 2024 11:36
Pure Javascript Cookies Management
// found on http://snipplr.com/view/36790/jscookies--my-simple-easy-pure-js-javascript-cookies-function/
// create my jsCookies function
var jsCookies = {
// this gets a cookie and returns the cookies value, if no cookies it returns blank ""
get: function(c_name) {
if (document.cookie.length > 0) {
var c_start = document.cookie.indexOf(c_name + "=");
if (c_start != -1) {
@jrivero
jrivero / csv_to_xml.py
Last active September 25, 2015 00:57 — forked from gcollazo/csvtoxml.py
#!/usr/bin/env python
# encoding: utf-8
"""
csv_to_xml.py
This script coverts a csv file to an XML.
The script takes 2 paramenters
* filename
* row node name
@jrivero
jrivero / control_daemon_repeat.php
Last active February 21, 2024 11:39
Control repeat of daemon
<?php
function control_daemon_repeat() {
$ps = "/bin/ps aux | /bin/grep -i ".$_SERVER["argv"][0]." | /bin/grep -v grep | wc -l";
$exec = exec($ps, $output, $return);
if ($output[0] > 1) die("*** Ya esta en ejecucion\n");
}
// Example
control_daemon_repeat();
@jrivero
jrivero / Autokill.php
Last active February 21, 2024 11:39
Kill process if is modified
<?php
class Autokill {
var $start_mtime_included_files = array();
function Autokill() { $this->__construct(); }
function __construct() {
clearstatcache();
$files = get_included_files();
<?php
class GenericVariable
{
private $var;
function __construct($variable)
{
$this->var = $variable;
}
function __get($var)
@jrivero
jrivero / HackerNewsRank.py
Last active February 21, 2024 11:39
Hacker News ranking algorithm
# From http://amix.dk/blog/post/19574
def calculate_score(votes, item_hour_age, gravity=1.8):
return (votes - 1) / pow((item_hour_age+2), gravity)
from django.core.paginator import ObjectPaginator
class QuickObjectPaginator(ObjectPaginator):
max_safe_pages = 0
def __init__(self, object_list, per_page, orphans=0, max_safe_pages=0):
self.max_safe_pages = max_safe_pages
super(QuickObjectPaginator, self).__init__(object_list, per_page, orphans)
def validate_page_number(self, page_number):