Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Writing if statements. Then, else.

Clemente Cuevas cuevasclemente

💭
Writing if statements. Then, else.
  • Erudite AI
  • Montreal, QC
View GitHub Profile
@cuevasclemente
cuevasclemente / sparql_query.py
Created Feb 21, 2017
Runs a sparql query on dbpedia
View sparql_query.py
#!/bin/env python3
## usage: ./sparql_query.py '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('http://dbpedia.org/sparql')
sparql.setQuery(query)
@cuevasclemente
cuevasclemente / get_wikipedia_page_text.sh
Created Feb 21, 2017
Process the output of processed wikipedia output
View get_wikipedia_page_text.sh
cat wiki_* | awk '!/<doc id/ || !/<\/doc/{print x, "\n";};{x=$0}' > wiki_text_extracted
View shuffle_playlist.py
#!/bin/env python
import sys
import random
if __name__ == '__main__':
old_indices = []
new_indices = []
with open(sys.argv[1]) as f:
pl = f.read().split("\n")
desired = []
for i in range(1, len(pl[1:]), 2)
@cuevasclemente
cuevasclemente / AddRepositoryToPacmanForYaourt
Created Feb 13, 2017 — forked from DenverDias/AddRepositoryToPacmanForYaourt
This snippet adds the repository to pacman that contains yaourt...
View AddRepositoryToPacmanForYaourt
[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch
@cuevasclemente
cuevasclemente / pgp.json
Last active Jun 27, 2016
json of the pgp table with integer keys (taken from https://github.com/warner/magic-wormhole/blob/master/src/wormhole/wordlist.py) All Rights Reserved
View pgp.json
{
"0": [
"aardvark",
"adroitness"
],
"1": [
"absurd",
"adviser"
],
"10": [
@cuevasclemente
cuevasclemente / header_collect.sh
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`
View header_collect.sh
$ for file in *.csv; do echo "${file%.csv},$(head -n 1 $file)" >> headers; done
@cuevasclemente
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) {
View elasticsearch_shutdown.sh
# 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
cuevasclemente / scp_remote_proxy_remote.sh
Last active Nov 17, 2015
SCP Between Remote1 and Remote2 (Remote2 behind proxy)
View scp_remote_proxy_remote.sh
# 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"
user1@remotehost1:/file/1
@cuevasclemente
cuevasclemente / sum_last_lines.sh
Created Nov 10, 2015
Sum of the matching part of the last line of a set of files
View sum_last_lines.sh
# 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}'