Skip to content

Instantly share code, notes, and snippets.

View agusmakmun's full-sized avatar
🏠
Working from home

agusmakmun

🏠
Working from home
View GitHub Profile
@agusmakmun
agusmakmun / simple_multi_line_string_parser.py
Created May 14, 2016 21:46 — forked from ihfazhillah/simple_multi_line_string_parser.py
parse multiline text untuk dijadikan pasangan katakunci dan value
"""Hi, ini adalah code snippet tentang parsing multiple line text
biasanya dipakai untuk file file konfigurasi.
Berikut adalah sample_text yang saya ingin buat spt ini:
{'COBA': 'sedang ini adalah coba\ncoba lagi\ncoba lagi',
'INITIAL': 'ini adalah initial\ndan ini adalah kalimat\njuga ini'}
dari: sample_text dibawah ini,
semoga bermanfaat, dan saya tidak bingung lagi....."""
sample_text = """####INITIAL####
@font-face {
font-family: "Proxima Nova";
src: url(data:font/opentype;base64,d09GRgABAAAAAEywABIAAAAAg3QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEWU5BAAAGbAAAALgAAAGJNI0oHkZGVE0AAAGUAAAAHAAAABxdnq2WR0RFRgAAByQAAAA4AAAAQgSqBTxHUE9TAAAHXAAABCIAABH0zI0AF09TLzIAAAXUAAAAVwAAAGCAz3p9Y21hcAAASvgAAAG2AAAC5lCJVL9jdnQgAAABsAAAAB4AAAAeCkcLCmZwZ20AAAHQAAABsgAAAmUjtC+nZ2FzcAAAA4QAAAAIAAAACAAAABBnbHlmAAALgAAAO4sAAF8I3FzIU2hlYWQAAAOMAAAANQAAADb9TDtqaGhlYQAABiwAAAAgAAAAJA9PBsBobXR4AABHDAAAAh8AAANsqw8hfGxvY2EAAEksAAABuAAAAbhtqYQ8bWF4cAAABkwAAAAgAAAAIAIDAhpuYW1lAAADxAAAAawAAANRLIw+gnBvc3QAAErkAAAAEwAAACD/DQAocHJlcAAABXAAAABjAAAAdNUcAaMAAAABAAAAAMmJbzEAAAAAyRrF1wAAAADK+niN/pAAAAPGBTYBYADCANABNgE+AWgBmQDkAZIBkAFYAAB42l1Ru05bQRDdDQ+TBBJjg+RoU8xmQhrvhYYCJBBXF8XIdmM5QtqNXORiXMAHUCBRg/ZrBmgoKdKmQcgFUj6BT0BiZk2iKM3Ozuycc+bMknKk6l1a73nqnARSuNOg2abfDql2FuCedH21kZF28EDzzYxeuW7ff8VgM5pyRw2gvOct5SGjaSdQi/bU/za/guE+/2Qeg0FLM01PrZOQHkJgvhm3MPie0ay7/KQvWB0uBgNDimkq7vJzKuV/S3Outgibaxm9dnAmIj+ZBmhqpY1A0186pHo+jmIJctkw1gYTU9afZCL4ZjJd1VQtM751cJfszDt
@agusmakmun
agusmakmun / streaming.py
Created June 1, 2016 21:34 — forked from ferayebend/streaming.py
twitter streaming
#!/usr/bin/python
# -*- encoding: utf-8 -*-
#from tweepy.streaming import StreamListener
#from tweepy import OAuthHandler
#from tweepy import Stream
import tweepy
import json
import codecs
import os
@agusmakmun
agusmakmun / trends.py
Created June 1, 2016 21:36 — forked from perone/trends.py
Trends Twitter
@agusmakmun
agusmakmun / search_twitter.py
Created June 1, 2016 21:37 — forked from kwellman/search_twitter.py
Mining twitter blog post (search_twitter.py)
import urllib, urllib2, json
def search_twitter(query, no_retweets=True):
if no_retweets:
# use the negation operator to filter out retweets
query += ' -RT'
url = 'http://search.twitter.com/search.json?%s' % urllib.urlencode({
'q': query,
'lang': 'en', # restrict results to english tweets
@agusmakmun
agusmakmun / search.txt
Created June 1, 2016 21:40
twitter api - search
Pinky on the cartoon "Pinky and the Brain" had a British accent because the producers were big fans of Monty Python.
----
Terry Gilliam laughs off Variety's dead Python blunder http://t.co/9axxZIjRPt
----
RT CoinfeedIO "#Bitcoin How to Program blockchain Explorers with Python, Part 1 http://t.co/GHNNNGJ0QT"
----
RT @HelenPaul_: PHOTOS: Man Kills Scary Gigantic Python Right Inside His House http://t.co/u6a3YidZbt
----
Why call an application #bash ? It just encourages abuse against computers. On the plus side, script is working #webdev #python
#bash
@agusmakmun
agusmakmun / medium_twitter_mining_7.py
Created June 1, 2016 21:41
medium_twitter_mining_7
from collections import Counter
# get top ten entities
top_words = [item[0] for item in Counter(words).most_common()[:10]]
top_words_freq = [item[1] for item in Counter(words).most_common()[:10]]
top_screen_names = [item[0] for item in Counter(screen_names).most_common()[:10]]
top_screen_names_freq = [item[1] for item in Counter(screen_names).most_common()[:10]]
top_hashtags = [item[0] for item in Counter(hashtags).most_common()[:10]]
top_hashtags_freq = [item[1] for item in Counter(hashtags).most_common()[:10]]
import twitter
import json
import pickle
import time
import random
import sys
import csv
import twitter__login
# log in, and collect statuses containing a keyword
@agusmakmun
agusmakmun / onlinenowMiddelware.py
Last active December 8, 2022 02:31 — forked from dfalk/onlinenow.py
django online users, usage: {{ request.online_now }} or {{ request.online_now_ids }}, usage: https://python.web.id/blog/django-count-online-users/
from django.conf import settings
from django.core.cache import cache
from django.contrib.auth.models import User
from django.utils.deprecation import MiddlewareMixin
ONLINE_THRESHOLD = getattr(settings, 'ONLINE_THRESHOLD', 60 * 15)
ONLINE_MAX = getattr(settings, 'ONLINE_MAX', 50)
def get_online_now(self):
return User.objects.filter(id__in=self.online_now_ids or [])
@agusmakmun
agusmakmun / gomodorokanbanreminder.py
Created August 13, 2016 01:46 — forked from goFrendiAsgard/gomodorokanbanreminder.py
Go Frendi's pomodoro, kanban, and reminder application. Work on terminal, written by using Python
import os, json, time, datetime, math, curses
#global variables
KANBAN_FILE = os.path.expanduser("~/.kanban.json")
DEFAULT_KANBAN = {
"tasks" : [],
"boards" : ["To do", "Doing", "Done"],
"work_time" : 25 * 60,
"rest_time" : 5 * 60
}