Skip to content

Instantly share code, notes, and snippets.

View cuevasclemente's full-sized 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 February 21, 2017 23:12
Runs a sparql query on dbpedia
#!/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 February 21, 2017 18:37
Process the output of processed wikipedia output
cat wiki_* | awk '!/<doc id/ || !/<\/doc/{print x, "\n";};{x=$0}' > wiki_text_extracted
@cuevasclemente
cuevasclemente / shuffle_playlist.py
Created February 15, 2017 06:55
Shuffle an m3u playlist`
#!/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 February 13, 2017 20:56 — forked from DenverDias/AddRepositoryToPacmanForYaourt
This snippet adds the repository to pacman that contains yaourt...
[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch
@cuevasclemente
cuevasclemente / pgp.json
Last active June 27, 2016 17:55
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
{
"0": [
"aardvark",
"adroitness"
],
"1": [
"absurd",
"adviser"
],
"10": [
@cuevasclemente
cuevasclemente / header_collect.sh
Created March 21, 2016 17:52
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
cuevasclemente / abstracted_reflection.go
Last active February 26, 2016 18:59
Functions that show Go reflection to write some abstracted code
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
cuevasclemente / scp_remote_proxy_remote.sh
Last active November 17, 2015 16:23
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"
user1@remotehost1:/file/1
@cuevasclemente
cuevasclemente / sum_last_lines.sh
Created November 10, 2015 22:15
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}'