Skip to content

Instantly share code, notes, and snippets.

View rosdyana's full-sized avatar
💭
I may be slow to respond.

Rosdyana Kusuma rosdyana

💭
I may be slow to respond.
View GitHub Profile
#!/bin/bash
if [ "$(whoami)" != "root" ]; then
echo "Sorry, you are not root."
exit 1
fi
echo "Stop all dokku--- Begin -->"
sudo dokku ps:stopall
echo "Stop all dokku--- End --/>"
#!/bin/bash
less -r $1 | env ansi2html.pl $3 > $2
#!/bin/bash
#set -x
# Shows you the largest objects in your repo's pack file.
# Written for osx.
#
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
This file has been truncated, but you can view the full file.
{"2004": "Afghanistan", "2008": "Albania", "2010": "Antarctica", "2012": "Algeria", "2016": "American Samoa", "2020": "Andorra", "2024": "Angola", "2028": "Antigua and Barbuda", "2031": "Azerbaijan", "2032": "Argentina", "2036": "Australia", "2040": "Austria", "2044": "The Bahamas", "2048": "Bahrain", "2050": "Bangladesh", "2051": "Armenia", "2052": "Barbados", "2056": "Belgium", "2060": "Bermuda", "2064": "Bhutan", "2068": "Bolivia", "2070": "Bosnia and Herzegovina", "2072": "Botswana", "2074": "Bouvet Island", "2076": "Brazil", "2084": "Belize", "2086": "British Indian Ocean Territory", "2090": "Solomon Islands", "2092": "British Virgin Islands", "2096": "Brunei", "2100": "Bulgaria", "2104": "Myanmar (Burma)", "2108": "Burundi", "2112": "Belarus", "2116": "Cambodia", "2120": "Cameroon", "2124": "Canada", "2132": "Cape Verde", "2136": "Cayman Islands", "2140": "Central African Republic", "2144": "Sri Lanka", "2148": "Chad", "2152": "Chile", "2156": "China", "2158": "Taiwan", "2162": "Christmas Island", "2166
def repeatedString(s, n):
number = s.count('a')
if number == 0:
return 0
if number == 1 and len(s) == 1:
return n
repeats = n//len(s)
remainder = math.floor(n%len(s))
return number*repeats+s[:remainder].count('a')
@rosdyana
rosdyana / remove_duplicates.py
Last active January 15, 2020 07:01 — forked from victorono/remove_duplicates.py
Django - remove duplicate objects where there is more than one field to compare
from django.db.models import Count, Max, Q
from django.db.models.functions import Length
from ma_audience.models import Audience
unique_fields = ['email']
duplicates = (
Audience.objects.filter(Q(organization_id=81), ~Q(email=''), Q(email__isnull=False)).values(*unique_fields)
.order_by()
.annotate(max_id=Max('id'), count_id=Count('id'))
from omnidata.models import *
from ma_audience.models import *
from django.db.models import *
from omnidata.models import Product as d_Product, Organization as d_Organization, Conversion, PageView
import collections
from datetime import timedelta
org = Organization.objects.get(id=1) # Ruby
d_org = d_Organization.objects.get(id=1)
# from remote to local
```
scp [email protected]:/remote/file.txt /local/directory
```
# from local to remote
```
scp file.txt [email protected]:/remote/directory
```
import pandas as pd
import sys
CHUNK_SIZE = int(sys.argv[2])
rows = pd.read_csv(sys.argv[1], chunksize=CHUNK_SIZE)
for i, chuck in enumerate(rows):
# i is for chunk number of each iteration
chuck.to_csv('out{}.csv'.format(i))
@rosdyana
rosdyana / postgres-cheatsheet.md
Created April 1, 2020 08:59 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)