Skip to content

Instantly share code, notes, and snippets.

Writing if statements. Then, else.

Clemente Cuevas cuevasclemente

Writing if statements. Then, else.
  • Erudite AI
  • Montreal, QC
View GitHub Profile
cuevasclemente /
Created Feb 21, 2017
Runs a sparql query on dbpedia
#!/bin/env python3
## usage: ./ 'select ?x where {[] a ?x} limit 100'
import json
import sys
from SPARQLWrapper import SPARQLWrapper, JSON
if __name__ == '__main__':
query = sys.argv[1]
sparql = SPARQLWrapper('')
cuevasclemente /
Created Feb 21, 2017
Process the output of processed wikipedia output
cat wiki_* | awk '!/<doc id/ || !/<\/doc/{print x, "\n";};{x=$0}' > wiki_text_extracted
#!/bin/env python
import sys
import random
if __name__ == '__main__':
old_indices = []
new_indices = []
with open(sys.argv[1]) as f:
pl ="\n")
desired = []
for i in range(1, len(pl[1:]), 2)
cuevasclemente / AddRepositoryToPacmanForYaourt
Created Feb 13, 2017 — forked from DenverDias/AddRepositoryToPacmanForYaourt
This snippet adds the repository to pacman that contains yaourt...
View AddRepositoryToPacmanForYaourt
SigLevel = Never
Server =$arch
cuevasclemente / pgp.json
Last active Jun 27, 2016
json of the pgp table with integer keys (taken from All Rights Reserved
View pgp.json
"0": [
"1": [
"10": [
cuevasclemente /
Created Mar 21, 2016
Shell one-liner to: Get the first row of a bunch of CSV files (ostensibly headers) and write them all to the same file, but with the first element of that file being the name of the file without `csv`
$ for file in *.csv; do echo "${file%.csv},$(head -n 1 $file)" >> headers; done
cuevasclemente / abstracted_reflection.go
Last active Feb 26, 2016
Functions that show Go reflection to write some abstracted code
View abstracted_reflection.go
package abstractreflection
import "reflect"
// Sum adds all the fields of `struct1` to `struct2`
// This will only work if the two structs are of the same
// type, and have flat properties
// that are all float64. If not, the result will be `nil`
func Sum(struct1 interface{}, struct2 interface{}) interface{} {
t := reflect.TypeOf(struct1)
if t != reflect.TypeOf(struct2) {
# Shutdown local node
$ curl -XPOST 'http://localhost:9200/_cluster/nodes/_local/_shutdown'
# Shutdown all nodes in the cluster
$ curl -XPOST 'http://localhost:9200/_shutdown'
cuevasclemente /
Last active Nov 17, 2015
SCP Between Remote1 and Remote2 (Remote2 behind proxy)
# SCP Protip: Ever needed to copy something between two remote
# servers with a proxy (like orbital) in between them? In one step (kinda?)?
# Try using this insane `scp` invocation to copy a file from remote host 1 to remote host 2
# which is behind a proxy gateway!
scp -v -3 -o "ProxyCommand ssh -A -o StrictHostKeyChecking=no
-o UserKnownHostsFile=/dev/null proxy_user@proxyhost nc remotehost2 port_for_remotehost_2"
-o "ForwardAgent=yes" -o "StrictHostKeyChecking=no"
-o "UserKnownHostsFile=/dev/null"
cuevasclemente /
Created Nov 10, 2015
Sum of the matching part of the last line of a set of files
# First, get the last line of each file (each log file)
# Then, pull the floating point number at the end of the line
# Then, collect the sum of `1/floating_point_number`. At the end, print
# s
tail -n 1 *.log | grep -e "[0-9]\.[0-9]*$" -o | awk '{s+=1/$1} END {print s}'