Skip to content

Instantly share code, notes, and snippets.

View Django initial tables postgres.sql
-- Name: auth_group; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE auth_group (
id integer NOT NULL,
name character varying(80) NOT NULL
);
@Ivanca
Ivanca / .zshrc
Created Nov 28, 2018
comand "make setup" to do make dev.clone && make dev.checkout && make dev.provision && make dev.up
View .zshrc
# put it on .bashrc (or .zshrc for zsh)
# comand "make setup" to do make dev.clone && make dev.checkout && make dev.provision && make dev.up
# optional parameter for devstack git repo to clone
make() {
if [[ $@ =~ ^setup.* ]]; then
sh -ec '
if [ "$2" != "" ]; then
git clone $2
cd devstack
fi
View brickset.com scrapper.py
import scrapy
class BrickSetSpider(scrapy.Spider):
name = 'brick_spider'
start_urls = ['http://brickset.com/sets/year-2018']
def parse(self, response):
SET_SELECTOR = '.set'
for brickset in response.css(SET_SELECTOR):
View tower-of-hanoi.py
def hanoi(n, source, helper, target):
print "hanoi( ", n, source, helper, target, " called"
if n > 0:
# move tower of size n - 1 to helper:
hanoi(n - 1, source, target, helper)
# move disk from source peg to target peg
if source[0]:
disk = source[0].pop()
print "moving " + str(disk) + " from " + source[1] + " to " + target[1]
target[0].append(disk)
@Ivanca
Ivanca / Q-adverts.py
Last active Feb 23, 2018
Q adverts translated to python
View Q-adverts.py
# Each-prior
#####################################################################
# in Q >>>
types: type'[(1;2h;3.2)]
# returns the type of each element (-7 -5 -9h)
# in PYTHON >>>
numbers = [1, 2, 3.2]
types = list(map(type, numbers))
@Ivanca
Ivanca / to-php56.sh
Last active Dec 9, 2017
Upgrading from php5.3 to php5.6 on Amazon Linux AMI
View to-php56.sh
#!/bin/bash
# Stop it all
sudo service httpd stop
sudo service php-fpm stop
# Remove problematic packages
sudo yum remove -y httpd httpd-tools apr apr-util
# Remove old php and php extensions
View HackerNews (news.ycombinator) ajaxLoadNextPage.js
(function ajaxLoadNextPage () {
var more = document.querySelector('.comment-tree > tbody > tr:last-child a');
if (more && more.innerHTML === "More") {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
more.remove();
var div = document.createElement('div');
div.innerHTML = httpRequest.responseText;
View flattenArray.js
// Flattens an array, e.g. [[1,2,[[[3]]]],4] => [1, 2, 3, 4]
var flattenArray = (array) => {
let initialValue = [];
return array.reduce((result, ele) => {
if (Array.isArray(ele)) {
let flat = flattenArray(ele);
return result.concat(flat);
} else {
result.push(ele);
return result;
@Ivanca
Ivanca / sorty by frequency.js
Last active Aug 1, 2017
Most common words (excluding
View sorty by frequency.js
function sortByFrequency(array) {
var frequency = {};
array.forEach(function(value) { frequency[value] = 0; });
var uniques = array.filter(function(value) {
return ++frequency[value] == 1;
});
return uniques.sort(function(a, b) {
return frequency[b] - frequency[a];
@Ivanca
Ivanca / scrapehn.js
Last active Nov 3, 2015
You would have to use this with a cronjob or something of the sort
View scrapehn.js
var casper = require('casper').create({viewportSize: {width: 960, height: 600}});
var fs = require('fs');
casper.start('https://news.ycombinator.com/', function() {
var now = this.fetchText('#hnmain');
var old = fs.read('old.txt');
if (old !== now) {
casper.open('http://text-compare.com/', {
method: 'post',
data: {'text1': old, 'text2': now}
You can’t perform that action at this time.