Skip to content

Instantly share code, notes, and snippets.

@lrhache
lrhache / models.py
Last active June 14, 2021 16:16
Metaclass examples
from collections import defaultdict
from typing import Type, cast, Callable, TypeVar, Any
from functools import wraps
T = TypeVar('T')
def wrap_setattr(definition: dict, fn: Callable) -> Callable:
@wraps(fn)
def wrapped(self, attr, value):
@lrhache
lrhache / sleep.js
Created February 26, 2021 19:26
NodeJs Sleep function
function sleep(n) {
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n*1000);
}
@lrhache
lrhache / list.md
Created December 19, 2020 13:07 — forked from ih2502mk/list.md
Quantopian Lectures Saved
@lrhache
lrhache / gist:92d8031e8df7f6133257869d775686aa
Created July 26, 2016 15:52
find string in files recursively without touching each files
grep -rl "oldstring" . | LANG=C LC_ALL=C xargs sed -i '' -e "s/oldstring/newstring/g"
@lrhache
lrhache / force-oauth.py
Created March 31, 2016 14:51
Another simple Python example with a real OAuth flow. This uses responses and the simple-salesforce lib
#!/usr/bin/python
import cgi
import requests
import json
from simple_salesforce import Salesforce
#login here:
#https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=3MVG9A2kN3Bn17hsWsLDatw._IVMEUBoPKv.7ksp0tz7xLX4tWDVgyzwTCA7i_yTfP.qYuNOsSoPNcdVH6DuE&redirect_uri=http://localhost/cgi-bin/python/oauth.py
@lrhache
lrhache / neo4j-install-ubuntu.sh
Last active March 6, 2018 02:17
neo4j util script
#!/bin/sh
sudo echo "export NEO4J_HOME=/opt/neo4j" >> /etc/environment
source /etc/environment
sudo mkdir -p $NEO4J_HOME
sudo chown ubuntu.ubuntu $NEO4J_HOME
cd /tmp
@lrhache
lrhache / neo-geo.py
Last active January 26, 2016 19:07
Neo4j geospatial python
import time
import random
import requests
from profilehooks import profile
def timeit(method):
def timed(*args, **kw):
ts = time.time()
@lrhache
lrhache / bitweekdays.py
Created January 8, 2016 15:37
Convert weekdays as bit representation
weekdays = ('Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday', 'Sunday', )
def convert_choice(*args):
"""Convert weekdays representation to 127 bits
Example:
>> # Monday, Tuesday, Friday, Sunday
>> bw.convert(1, 1, 0, 0, 1, 0, 1)
@lrhache
lrhache / ElasticSearch.sh
Last active September 2, 2015 13:22 — forked from ricardo-rossi/ElasticSearch.sh
Installing ElasticSearch on Ubuntu 14.04
#!/bin/bash
### USAGE
###
### ./ElasticSearch.sh 1.7 will install Elasticsearch 1.7
### ./ElasticSearch.sh will fail because no version was specified (exit code 1)
###
### CLI options Contributed by @janpieper
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch
@lrhache
lrhache / missing-lines.sh
Last active August 29, 2015 14:19
Find all the missing lines from file B that are in file A
grep -F -x -v -f <file to compare:file B>.txt <base file:file A>.txt
# or:
comm <(sort fileB) <(sort fileA) -3 > output.txt
# prints lines that are both in file1 and file2 (intersection)
awk 'NR==FNR{a[$0];next} $0 in a' file1 file2