Skip to content

Instantly share code, notes, and snippets.

@glpunk
glpunk / git.sh
Last active March 28, 2019 14:58
Git Commands #GIT
# git delete branch with force
git branch -D branch_name
# git rename branch
git branch -m <oldname> <newname>
# ... or if the current branch
git branch -m <newname>
# change up stream
@glpunk
glpunk / user.sh
Created April 29, 2016 17:50
Creating ssh user
sudo /usr/sbin/useradd --shell /bin/bash --home /home/adminwebsite -g www-data adminwebsite
sudo mkdir /home/adminwebsite
sudo chown -R adminwebsite:www-data /home/adminwebsite
sudo chmod 0700 /home/adminwebsite
sudo passwd adminwebsite
@glpunk
glpunk / utopiantree.rb
Created November 19, 2014 00:44
utopian tree example
#!/usr/bin/ruby
class Utopiantree
def cycle n
size = 1
if n > 0
for val in 0..n-1
@glpunk
glpunk / isfibo.py
Created November 19, 2014 00:41
python fibonacci example
def genFibo(arr):
arr.append( arr[-1]+arr[-2] )
def isFibo(n, fibos):
if n in fibos:
foo = 'IsFibo'
else:
foo = 'IsNotFibo'
return foo
@glpunk
glpunk / linux.sh
Last active August 29, 2015 14:02
Linux
#find string inside files
grep -rnw 'directory' -e "pattern"
#replaces string inside files, recursive
cd /home/www
find . -type f -print0 | xargs -0 sed -i 's/split(/explode(/g'
@glpunk
glpunk / method_missing_test.rb
Last active September 7, 2018 14:03
getter and setter through method_missing to manipulate a hash inside a ruby class #ruby
class Test
def initialize
@hash = {prop1: 'prop 1 value', prop2: 'prop2 value'}
end
def method_missing(m, *args)
#setter
if /^(\w+)=$/ =~ m
@hash[:"#{$1}"] = args[0]
end
@glpunk
glpunk / gist:8043266
Last active December 31, 2015 20:58
mongodb aggregate example. First query counts documents by country. Second, counts documents by date
db.contests_tbbt2013.aggregate(
{ $group: {_id: "$country", total: {$sum: 1} } }
);
db.contests_tbbt2013.aggregate(
{$group:
{
_id:{ $dayOfYear:'$regdate' },
sum:{$sum:1},
date:{$first: '$regdate'}
@glpunk
glpunk / gist:7709655
Created November 29, 2013 18:03
copy mongodb database in localhost, run in shell.
db.copyDatabase("test","test_copy","127.0.0.1");
@glpunk
glpunk / scrapper.sh
Created November 20, 2013 18:10
Automatic torrent download from glowgaze.com with transmission-remote (raspberry pi)
#!/bin/bash
#save HTML content to file.html
curl -o /tmp/file.html http://glowgaze.com/
#search by grep content in file.html
function get {
arr=(`cat /tmp/file.html | grep -o -E '(goto-+([0-9]*-)('$1')(\w)*)'`)
echo ${arr[0]}
@glpunk
glpunk / exportusers.php
Created July 18, 2013 21:21
PHP: error reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');