Skip to content

Instantly share code, notes, and snippets.

View decebal's full-sized avatar
🥑

Decebal Dobrica decebal

🥑
View GitHub Profile
@BartoszCki
BartoszCki / beautiful_idiomatic_python.md
Last active May 18, 2018 12:38 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@mmellison
mmellison / grpc_asyncio.py
Last active April 3, 2024 15:48
gRPC Servicer with Asyncio (Python 3.6+)
import asyncio
from concurrent import futures
import functools
import inspect
import threading
from grpc import _server
def _loop_mgr(loop: asyncio.AbstractEventLoop):
@d2s
d2s / installing-node-with-nvm.md
Last active March 13, 2024 12:09
Installing Node.js to Linux & macOS & WSL with nvm

Installing Node.js with nvm to Linux & macOS & WSL

A quick guide on how to setup Node.js development environment.

Install nvm for managing Node.js versions

nvm allows installing several versions of Node.js to the same system. Sometimes applications require a certain versions of Node.js to work. Having the flexibility of using specific versions can help.

  1. Open new Terminal window.
@cristobal
cristobal / machine-diskutil.sh
Last active February 27, 2024 23:36
Machine Diskutil to mount/unmont external volumes inside docker machines running on Virtualbox
#!/usr/bin/env sh
# @see http://stackoverflow.com/questions/30040708/how-to-mount-local-volumes-in-docker-machine
# @see https://github.com/boot2docker/boot2docker/blob/master/doc/FAQ.md
################################################################################
# Dependency Section #
# #
################################################################################
check_deps() {
## Make sure commands are available
@bobuss
bobuss / Calisthenics.md
Last active March 31, 2024 09:41
The 9 Rules of Object Calisthenics

Object Calisthenics outlines 9 basic rules to apply when performing the exercise:

  • One level of indentation per method.
  • Don't use the ELSE keyword.
  • Wrap all primitives and Strings in classes.
  • First class collections.
  • One dot per line.
  • Don't abbreviate.
  • Keep all classes less than 50 lines.
  • No classes with more than two instance variables.
@getify
getify / gist:3667624
Last active June 25, 2022 16:26
escape all (not-already-escaped) double-quote chars in a string
// NOTE: only escapes a " if it's not already escaped
function escapeDoubleQuotes(str) {
return str.replace(/\\([\s\S])|(")/g,"\\$1$2"); // thanks @slevithan!
}
escapeDoubleQuotes(`ab`); // ab => ab (nothing escaped)
escapeDoubleQuotes(`a"b`); // a"b => a\"b
escapeDoubleQuotes(`a\\"b`); // a\"b => a\"b (nothing escaped)
escapeDoubleQuotes(`a\\\\"b`); // a\\"b => a\\\"b
escapeDoubleQuotes(`a\\\\\\"b`); // a\\\"b => a\\\"b (nothing escaped)
@decebal
decebal / remote.php
Created January 27, 2012 15:40
display errors on dev ip
if($_SERVER['REMOTE_ADDR'] == '86.120.211.231'){
ini_set("display_errors", 'On');
error_reporting(E_ALL ^ E_NOTICE);
}else{
ini_set("display_errors", 'Off');
}
@kylebgorman
kylebgorman / KMP.py
Created September 20, 2011 00:30
The Knuth-Morris-Pratt algorithm in Python
#!/usr/bin/env python
# Knuth-Morris-Pratt demonstration
# Kyle Gorman <kgorman@ling.upenn.edu>
#
# A naive Python implementation of a function that returns the (first) index of
# a sequence in a supersequence is the following:
def subsequence(needle, haystack):
"""
Naive subsequence indexer; None if not found
@robflaherty
robflaherty / csv-to-json.php
Created September 1, 2011 02:26
Convert CSV to JSON
<?php
/*
* Converts CSV to JSON
* Example uses Google Spreadsheet CSV feed
* csvToArray function I think I found on php.net
*/
header('Content-type: application/json');
// Set your CSV feed