Skip to content

Instantly share code, notes, and snippets.

View aj07mm's full-sized avatar

Julio Marins aj07mm

View GitHub Profile
@aj07mm
aj07mm / WhatHappenedToMyDataInRedis.md
Created June 22, 2018 01:33 — forked from JonCole/WhatHappenedToMyDataInRedis.md
What happened to my data in Redis?

What happened to my data in Redis?

This post is a FAQ for Redis, when users don’t see the data they stored in Redis.

As per the Redis project, Redis is described as an in-memory data structure store. If you are using Redis as an LRU cache, you can see following recommendation from the Redis docs: Using Redis as an LRU cache

Lately, I have received multiple questions about when Redis will lose data. This data loss can be as simple as a few keys disappearing unexpectedly or complete loss of all data in Redis. Below I will talk about the most common causes as well as a few rare cases where this can happen.

Note: These scenarios are common to all Redis hosting environments, including self-hosting Redis in your own data center.

@aj07mm
aj07mm / commute.clj
Created June 9, 2018 18:00
commute.clj
(ns testing.core)
(def start (atom 0)) ; Record start time.
(def c1 (ref 0)) ; Counter 1
(def c2 (ref 0)) ; Counter 2
(def c3 (ref 0)) ; Counter 3
(defn milliTime
"Get current time in millisecond."
@aj07mm
aj07mm / ref-dosync-commute.clj
Last active June 9, 2018 14:03
ref-dosync-commute.clj
(defn sleep-print-update
[sleep-time thread-name update-fn]
(fn [state]
(Thread/sleep sleep-time)
(println (str thread-name ": " state))
(update-fn state)))
(def counter (ref 0))
; -------------
(future (dosync (commute counter (sleep-print-update 100 "Thread A" inc))))
;Thread A: 0
@aj07mm
aj07mm / macro.clj
Last active June 5, 2018 22:53
macro.clj
(defmacro print-1
[expr]
(let [result expr]
(println result)
result))
(defmacro print-2
[expr]
(list 'let ['result expr]
(list 'println 'result)
@aj07mm
aj07mm / datomic.md
Created May 25, 2018 01:21
datomic.md

Connecting to the Memory database This will mostly be a straight translation of the tutorial code, with comments where things aren't obvious.

;; Import the Datomic Peer library (usable as 'Peer' from here on) (import datomic.Peer)

;; Create the in memory database, calling the static class method Peer#createDatabase (def uri "datomic:mem://hello") (Peer/createDatabase uri)

@aj07mm
aj07mm / phone_matchup.py
Last active May 24, 2018 15:02
phone_matchup.py
import unittest
import re
from collections import defaultdict
"""
The phone matchup coding test.
A phone company keeps record of all calls that have been successfully
established. For these calls, the company registers
whether they fail mid-call or complete successfully. We are interested in
@aj07mm
aj07mm / savejsoninredis.py
Created May 18, 2018 03:05 — forked from swdevbali/savejsoninredis.py
Simply json.dumps() => save to redis => redis.get => json.loads() => Python dict with proper data type created
__author__ = 'ekowibowo'
import json
import os
import redis
REDIS_HOST = os.getenv('SS_ABTEST_REDIS_HOST', '192.168.59.103')
r = redis.StrictRedis(host=REDIS_HOST)
for k in r.keys('abtest:experiments:*'):
r.delete(k)
@aj07mm
aj07mm / adding_cider.txt
Created May 12, 2018 19:50
adding_cider.txt
The following has been tested to work on an `emacs -Q` session:
1. Launch `emacs -Q`
2. Add the below in the scratch buffer:
<!-- language: lang-el -->
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
@aj07mm
aj07mm / default.py
Created May 12, 2018 14:26
default.py
from django.db import models
class Post(models.Model):
def generate_slug(self):
return self.name + 'asdasdasdasd123'
name = models.CharField(max_length=255)
description = models.TextField()
attachment = models.FileField()